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 🙂