Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries. Thanks for all your past and future contributions.

Revision as of 19:59, 14 September 2013 by lpvalente (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to resume a Java ME application when a phone call or message is received

From Wiki
Jump to: navigation, search
Article Metadata
Created: vinuk4u (01 Apr 2011)
Last edited: lpvalente (14 Sep 2013)


When Java ME applications are running in a device and a phone call or message is received, the application will restart from beginning in many devices. This happens with games too. The background process in such scenario is that the operating system (OS) will call the startApp() method in our MIDlet class and our application will restart. This article demonstrates how to handle this situation.

Alternatives for resuming your application

So in order to handle this situation, there are at least two alternatives:

  1. You can save the application state in RMS continuously while running the application. And if a call or message or any hindrance occurs and the startApp() method is called again by the OS, then we need to check the state written in RMS and respond accordingly.
  2. The second alternative is a more tricky but easy way. In this case, what we need to do is to read-out the Display object to our public-global variable used in our application.

Steps to follow:

  1. Create a public object for javax.microedition.lcdui.Display
    public Display display = null;
  2. Fetch the value javax.microedition.lcdui.Display to this object.
    display = Display.getDisplay(this);
  3. Then call the appropriate Class for further procedure.

Step (ii) and (iii) should check the when the object variable is null. Also, don't make display null anywhere in the application, other than for minimizing the application.

Code Snippet

import javax.microedition.lcdui.Display;
import javax.microedition.midlet.*;
public class SampleMidlet extends MIDlet
public Display display = null;
public ApplicationClass applnClass = null;
public void startApp()
if(display == null)
display = Display.getDisplay(SampleMidlet.this);
applnClass = new ApplicationClass(SampleMidlet.this);
public void pauseApp()
public void destroyApp(boolean unconditional)

--vinuk4u 09:08, 1 April 2011 (UTC)

Try this out in your applications and let me know how much beneficial this article was to you.

This page was last modified on 14 September 2013, at 19:59.
23 page views in the last 30 days.