You can save and read files in the internal storage as private files which only your app can see except for other apps with root privileges. Continue reading “Saving and reading files in the internal storage”
The intensive use of many images in an app can create difficulties to the responsiveness and to memory, shown by warnings like ANR (Application Not Responding) or errors like OutOfMemoryError. Continue reading “The class LruCache to manage a cache of bitmap objects”
In Android in order to avoid to do too work in the main thread, most of the operations should be carried out in a secondary thread or a class that extends AsyncTask; then the final results are reported in some view to be shown to the user using Activity.runOnUiThread(Runnable) or View.post(Runnable) (see Processes and Threads) or Handler.handleMessage() (see Communicating with the UI Thread). Continue reading “Avoiding too frequent updates to the views”
If you want to reset or change preferences of an app at the first start here is an example of code you can put in an event as onCreate of the main activity:
Continue reading “Resetting the preferences on first launch of an app”
In an android app an activity is created and then destroyed, for example when the user open another activity or when the user presses the back button, later the user opens again the same activity that is is recreated using the data saved before the earlier destruction of the activity.
The data are saved in an object Bundle in the onSaveInstanceState method and restored in the onRestoreInstanceState method (see Recreating an Activity).
The Bundle class provides several setter and getter methods to save and restore data such as getInt and setInt for the integers and similar methods for other types of primitives, strings and one dimensional array.
In this post I write some examples to save and restore more complex objects such as the following CustomObject: Continue reading “Restoring complex objects at restart of an activity”
In December 2012 I wrote a post about an app that displays the sensor list in an android device, now after about a year and a half the API 19 have new sensor types and methods and I thought to update the app.
Continue reading “List of the sensors in a device”
In this post I explain a simple example of an implementation of a double tap event on an ImageView that can be adapted with some changes for a TextView or an Activity.
Continue reading “Implementing the double tap on an ImageView”
I implemented a Time Picker in the preference using the code found here where the class TimePreference extends the class DialogPreference but I found a lack of alignment with the other preference items because of a different setting of the margins and/or padding.
Continue reading “Padding and margin in DialogPreference”
In the previous post Handling the multi-touch in a view I’ve used a class that extends a View to show the circles where the screen is touched, here I display the same example but using a SurfaceView.
Continue reading “Handling the multi-touch in a surface view”