Random Android Gradle Tip: Different Icon per BuildType

Say you want to tell if the version of your installed app is a debug or release version just by looking at the icon on your device. Quick way to do this is to leverage Gradle’s Build type concept.
Build types allow you to create different versions of the same app from the same project. All projects have by default, a debug and release build type. If you want to have a different debug icon from your release icon.

All you have to do is create your launcher icon (debug version) and instead of placing the drawables in the main source set you would install them in the debug source-set. When your project is built in debug mode it would use the matching assets in the debug folder instead of the assets in main source folder. When you build the release version it will use the assets in the release folder if it exists or use the default ones in the main source set. This also holds for build variants.

[1] http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Build-Variants


Random Android Tip: ADB (Android Debug Bridge)

The Android Debug Bridge (adb) is a powerful tool that allows you to communicate with a connected device. One of my favorite features is the ability to start an Activity , BroadcastReceivers or Service while passing intent parameters to it, all from command line.
e.g starting an activity takes the form:

adb shell am start  -n “[your package name here]/[your activity path here]”

Take a look at the attached gist to see how you can do this.

[1] https://gist.github.com/ckurtm/ea4ba85c1dfc7be4a43b
[2] http://developer.android.com/tools/help/shell.html

Marking your Activities,Services and Receivers as exported in your app manifest might not be something you want to do in a production app as it might be a security risk if you do not wish to share you app info with any other app.

Android Random Perfomance Tip: Replace Enums

Enums on Android might require more than twice the memory as compared to static constants.
Replace enums in your code with static constants. The Android support annotations provide some useful annotations to help you catch bugs and check that you’re using the expected values for your static constants just like enums would , without the overhead.
[1] https://goo.gl/HPKBUw
[2] http://tools.android.com/tech-docs/support-annotations

Android Tint Drawables

Instead of adding multiple image assets that differ only in color to your androd project. Use only 1 asset and use TintDrawables to change the color.  e.g.:

public static void setImageColor(ImageView image,int color){
DrawableCompat.setTint(image.getDrawable(), color);

see the below gist for an example:
[1] https://gist.github.com/ckurtm/8e185ad9b4df9c0f98d1
[2] https://developer.android.com/reference/android/support/v4/graphics/drawable/DrawableCompat.html#setTint(android.graphics.drawable.Drawable, int)

Random Android Gradle Tip: App dependencies

If you need to see the dependency tree for your project you can run:
./gradlew :app:dependencies
./gradlew :app:androidDependencies
if you need to solve a conflict you could either exclude the conflicting module or use a resolution strategy to force a particular version of the library to be used .


Android TV Dialog

The leanback library for Android TV introduced the concept of guided step fragments. These have an intuitive way of presenting prompts to a user. I made a simple class that uses a GuidedStepFragment to create a simple yes/no dialog for TV. check out the git repo below



Native Dialog

TV dialog:

TV Dialog

I made the news!!… well my app did

Android Central wrote an article about my workout app,  365 Body Workout.


You should try it out 🙂