Namespaces
Variants
Actions

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

Jump to: navigation, search
Article Metadata

Article
Created: vinuk4u (01 Apr 2011)
Last edited: hamishwillee (19 Jul 2012)

Overview

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.

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()
{
display.setCurrent(null);
}
 
public void destroyApp(boolean unconditional)
{
notifyDestroyed();
}
}

--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 19 July 2012, at 09:43.
115 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved