×
Namespaces

Variants
Actions
(Difference between revisions)

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

From Nokia Developer Wiki
Jump to: navigation, search
hamishwillee (Talk | contribs)
m (Hamishwillee - Fix categories)
lpvalente (Talk | contribs)
m (Lpvalente -)
 
Line 22: Line 22:
 
== Overview ==
 
== 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.
+
{{Abstract|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 [[Midlet basic lifecycle and states|startApp()]] method in our MIDlet class and our application will restart. This article demonstrates how to handle this situation.}}
 
+
The background process in such scenario is that the operating system (OS) will call the [[Midlet basic lifecycle and states|startApp()]] method in our MIDlet class and our application will restart.
+
  
 
== Alternatives for resuming your application ==  
 
== Alternatives for resuming your application ==  

Latest revision as of 22:59, 14 September 2013

Article Metadata
Article
Created: vinuk4u (01 Apr 2011)
Last edited: lpvalente (14 Sep 2013)

[edit] 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. This article demonstrates how to handle this situation.

[edit] 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.

[edit] 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 14 September 2013, at 22:59.
103 page views in the last 30 days.