Categories
Android

Restoring complex objects at restart of an activity

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:

Categories
Java

Stopping the threads

Starting a thread is very easy in java, after you create it you need to call the method start(), for example:

where MyRunnable is a class implementing the Runnable interface overidden the method run().

Categories
Android

List of the sensors in a device

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.

Categories
Android

Implementing the double tap on an ImageView

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.

Categories
Android

Padding and margin in DialogPreference

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.

Categories
Java

Copying an array in java

In this post I show some ways to copy arrays of primitive data and objects to another array.

Categories
Android

Handling the multi-touch in a surface view

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.

Categories
Android

Handling the multi-touch in a view

In this post you find a full example about how to

  • extend a view to draw, in this case, a circle where you touch the screen
  • implement a listener on a view to handle the multi-touch
Categories
Android

Displaying notifications and progress bar from an instance of AsyncTask

The AsyncTask class is used to perform background tasks and it might be useful to show notifications and progress bars to alert the user.
In this post I write an example where I create two AsyncTask instances showing a startup notification, a progress bar and a notification of completed task

Categories
Lotus

How to change the look and feel of a view using css

A lotus view open in a browser is very ugly but you can greatly improve using stylesheets (css); here I explain how to use the css in a lotus view in order to improve the look and feel and to display rows in alternate colors.