Checking whether the current thread is the UI/Main thread or some other background thread is very easy. Here’s the code for it:
Continue reading “How to Check/Detect Whether Current Thread is UI/Main Thread or Not in Android”
Web and Mobile Development articles
Checking whether the current thread is the UI/Main thread or some other background thread is very easy. Here’s the code for it:
Continue reading “How to Check/Detect Whether Current Thread is UI/Main Thread or Not in Android”
There are times when you want to have a scrollable ViewGroup like a ViewPager or a ListView or a GridView inside another scrollable ViewGroup like a ScrollView. You could have various combinations like a ViewPager in a ListView, a ViewPager and a ListView inside a ScrollView (this is what I had to do in my Android app), etc. in your application.
On my journey of learning Android Development, I’ve realised that it is really important to understand the input handling especially how the entire touch events framework work. Wrapping your head around the entire propagation of touch events (including the gesture) is imperative else while coding you’ll find yourself stumped by the behaviour of different ViewGroups (or Views) when attaching touch listeners to them with the hope that your code works as expected when they actually won’t. It gets even tricker when you have ViewGroups like ViewPager or ListView (both scrollable) inside other scrollable ViewGroups like ScrollView.
If you’re running your application in the Android Emulator and suddenly the Hierarchy Viewer stops loading up the View Hierarchy in the standalone tool or in Android Device Monitor then chances are high that ADB server needs to be restarted in order to fix it.
You might be thinking showing up a View like TextView, ImageView, EditText, Button, etc. or a ViewGroup (wrapping other Views) like RelativeLayout or LinearLayout below a ListView/GridView must be easy. It’s not. Not in Android atleast.
Continue reading “Android Add Views or View Groups Below a ListView or GridView”
Android allows us to store files in its file system which is quite similar to any other Linux filesystem that you must have experience with. Using the java.io
file input/output APIs we can start reading and writing files to the Android filesystem. This is super useful when you want a store files (but not relational data or some sort of key/value cache pairs) on the device. Files like audio, video, images, documents, etc. all makes sense to store in the file system when required.
Continue reading “Android Saving Files on Internal and External Storage”
Android has a concept of shared preferences using which application preferences data can be stored persistently. That means the data or state won’t be lost until the application is uninstalled. The preferences data can be stored as key/value pairs and are available across all the Activities of the given application or can also be restricted to a particular Activity.
Continue reading “Android Application Data Storage With SharedPreferences”