Nov 9, 2009

ActivityMIDlet: A MIDlet++

Hi all,

In the post "Life Cycle Methods: Do you use them?", I wrote about MIDlet's life cycle methods. Also in this post, I quickly mentioned how interesting is the life cycle of an Activity in Android platform. I said that, because an Activity provides more life cycle methods, providing more control and possibilities for the developers. For instance, an Activity has 7 life cycle methods, against only 3 of a MIDlet. With numbers, nobody discusses, right? To understand more about an Activity's life cycle, click here.

Anyway, after having written that post, I decided to implement a custom MIDlet that provided as many life cycle methods as possible as an Android's Activity. Unfortunately, not all methods were possible to put in this class; onRestart() and onStop() do not fit for Java ME, since it does provide a state where an application is shut down and restart by own application manager. That's why I left it out.

On the other hand, I haved added onCreate() and onResume(). The first one works like a constructor and the second is called when the application returns to the foreground, after a certain period on pause. In addition, the method's invoking order is such an Activity.

Other interesting method that I have added is onLowMemory(). This notifies the application when it is running on low memory level, allowing the application to take any providence to avoid crashing. This memory level can be configured by setMinimumMemory(long) method. For further information about these new methods, check the Javadoc.

To download the ActivityMIDlet class, click here. I hope you guys enjoy it.

See you in the next post...

1 comment:

Anonymous said...

This is indeed interesting. I have a similar idea of hiding the MIDlet class, which can be viewed here:
http://blog.jayway.com/2009/12/11/java-me-the-lost-application/

--Darius