Android Themes, Styles and Attributes

One thing that bugs me from time to time is the appearance and disappearance of the Action bar or the change in its UI with similar XML code and Java API calls but with different themes. I was somehow managing till now but then decided that it’s probably a good time to understand the concept of themes and styles in android to make sure I know why there’s that frustrating difference just by a small change in the theme name (res/values/styles.xml then used in AndroidManifest.xml) that you sometimes do not even realize while creating new projects as it is set automatically based on the API levels you target.

Continue reading “Android Themes, Styles and Attributes”

Saving User Settings with Android Preferences (PreferenceActivity, PreferenceFragment, Headers)

An Android application will often need to have a dedicated section (page/Activity) where the user should be able to modify the app settings like enable/disable notifications, backup and sync data with cloud, etc. or changing preferences that’ll make the app behave differently because of various contexts you set like your name, profile pic, gender, birth date, etc. This also allows the app to dynamically generate the UI with the contextual details as well as use them for other purposes like “show me offers between $10-$100 only” or “I want to see people aged 15-25”. To achieve this, either you can definitely build your own set of Activities and layouts and manage a lot of the backend operations like CRUD all by yourself or use the Preference API to quickly build an interface that has the same look and feel as the System Settings app where you go to change all your phone settings.

Continue reading “Saving User Settings with Android Preferences (PreferenceActivity, PreferenceFragment, Headers)”

Android Debug Bridge (adb) Wireless Debugging Over Wi-Fi

We mostly connect our Android device to our computers with a USB cable for debugging purposes. It is possible to use adb over a wifi connection than a USB to save some wire-related hassles in our lives. The process is super simple, let’s go through it quickly.

Continue reading “Android Debug Bridge (adb) Wireless Debugging Over Wi-Fi”

Android/Java Multi-Threaded Execution with the Executor Framework (ThreadPoolExecutor)

These days CPUs with multiple cores have almost become the standard in Android devices. This means multiple operations (could be long running and resource intensive tasks) doesn’t have to wait to be executed on a single thread. They can rather run on multiple threads in parallel where each threads gets executed on a single processor. For example imagine an operation where multiple images have to be downloaded and shown in a gallery view. The downloads and any decoding required for different images could happen concurrently on multiple threads speeding up the entire operation, leading to a faster app experience.

Continue reading “Android/Java Multi-Threaded Execution with the Executor Framework (ThreadPoolExecutor)”

Android Background Services with IntentService

We’ve discussed Services before that run on the application’s UI (main thread). Android provides us with IntentService (extends the Service class) that has all the properties of a Service’s lifecycle with increased process rank and at the same time allows processing tasks on a background (worker) thread. So using an IntentService you can run long-running operations in the background without affecting the app’s responsiveness and at the same time one of the biggest advantage of it is that, it isn’t affected by most of the user interface (Activity/Fragment) lifecycle events, hence continues to run even when the Activity is destroyed for instance.

Continue reading “Android Background Services with IntentService”

Understanding Android AsyncTask (Executing Background Tasks)

The AsyncTask Android class lets us sort of bind background tasks to the UI thread. So using this class, you can perform background operations and then publish the results to the UI thread that updates the UI components. This way you won’t have to deal with threads, handlers, runnables, etc. directly yourself. It’s sort of a helper class around Thread and Handler.

Continue reading “Understanding Android AsyncTask (Executing Background Tasks)”

Understanding Android/Java Processes and Threads Related Concepts (Handlers, Runnables, Loopers, MessageQueue, HandlerThread)

In this article we’ll try to briefly go through the various sort of low level concepts in Android that are really important to understand IMHO. Once you have a good grasp on these, a lot of things that are actually built atop these concepts become much easier to understand and code. We’ll go through processes, threads, loopers, message queues, messages, handlers, runnables, etc. I’ll also point to various external resources that you should definitely go through for a much better understanding.

Continue reading “Understanding Android/Java Processes and Threads Related Concepts (Handlers, Runnables, Loopers, MessageQueue, HandlerThread)”