In my current project at work, I had a task to add run time permissions in an android app whose code is very old and using legacy methods and frameworks/tools. Normally, I use Ted Permissions in all my apps for the runtime permissions and I must say that it’s one hell of an amazing library I ever saw and given the complex scenario and flow of runtime permissions in Android (thanks to Google who always makes sure to make every thing more complicated than ever), this library makes the runtime permissions like a breeze.

Continue reading

Today, when I was working on a project, so I had a situation where I had to perform a very tiny operation in background in Android. I had lots of ideas such as AsyncTask or Thread or using such powerful framework like RxJava or using new APIs such as JobDispatcher or WorkManager etc. You can read about these options in this good article by Ali Muzaffar. But my major concern was that my requirement was a very simple and little one.

Continue reading

Today, I had a huge Json in my app and I wanted to fetch all these values in a general way. I also wanted to parse Json for only one time to avoid try/catch each time I access any value. So, first thing I had in mind was to convert the JSONObject in the HashMap or Map<> etc. So if you are using Gson in your apps for json mapping, then you can use this one line code for conversion.

Continue reading

Encrypt Strings Please copy the AESUtils class in your project first and then you can use it like this. String encrypted = ""; String sourceStr = "This is any source string"; try { encrypted = AESUtils.encrypt(sourceStr); Log.d("TEST", "encrypted:" + encrypted); } catch (Exception e) { e.printStackTrace(); } Decrypt Strings Please copy the AESUtils class in your project first and then you can use it like this. String encrypted = "ANY_ENCRYPTED_STRING_HERE"; String decrypted = ""; try { decrypted = AESUtils.

Continue reading

We often use View’s visibility in our apps to show and hide them. We use void setVisibility(int visibility) method for that purpose. But have you ever thought that why this method always takes VISIBLE, INVISIBLE and GONE rather than any int value like 0 or 1 etc.? Although method’s parameter type is int, then why it doesn’t accept the direct numbers or any other int variable except those three. In java, enum is known concept, and in many cases you can use it, but for android, enum is something you should avoid to use as it’s processing performance is not efficient, so in Android performance patterns it’s told to avoid enums and to use annotations like @IntDef and @StringDef.

Continue reading

Author's picture

Wajahat Karim

Android Developer. Open Source Contributor. Writer. Speaker

Senior Android Developer

Karachi, Pakistan