Example: BlackBerry Real background Running program, task inside can't see OH

Source: Internet
Author: User
Tags home screen

Description
The 1.blackberry_app_descriptor.xml Setup program is auto-run on Startup,do not display the application icon on the BlackBerry home screen

2. The mobile phone after the boot automatically run Backgroundapplication

3. Main program backgroundapplication in Main, execute Backgroundthread.waitforsingleton (). Start ();

4.BackgroundThread is also extends application, which has a thread running in the back, a dead loop, or listening to push data or other system events--geographic Change/Mobile radio network connection, and so on. Here is every 5 seconds in the cell phone log to write something.

5. Note that both the main program and the threaded programs are extends application

6. To eject the window, you must call Invokelater (new Runnable () {

Tips:

The core is to extends application

But I don't know if both the main program and the threaded programs need extends application

Details also need to figure out and test, comrades still need to work hard, hehe. Have a nice weekend.

/******************************************************************************************/
Main program:

Import net.rim.device.api.system.Application;

Class Backgroundapplication extends Application {
public static void Main (string[] args) {
Backgroundthread.loggerinit ();
BackgroundThread.log ("Main () Loggerinit");
Backgroundthread.waitforsingleton (). Start ();
}

Public Backgroundapplication () {
}
}

/******************************************************************************************/
Run the program in the background:

Class Backgroundthread extends Application {
public static String AppName = "Backgroundthread";
public static long GUID = 0xcf891935c91e1987l;
Private Listenerthread mythread;

Public Backgroundthread () {
Mythread = new Listenerthread ();
}

/******************************************************************************************
* BackGround Waitforsingleton ()-Returns an instance of a listening thread
******************************************************************************************/
public static Backgroundthread Waitforsingleton () {
Log ("Waitforsingleton");
Make sure this is a singleton instance
Runtimestore store = Runtimestore.getruntimestore ();
Object o = store.get (GUID);
if (o = = null) {
Log ("inited");
Store.put (GUID, New Backgroundthread ());
Return (Backgroundthread) store.get (GUID);
} else {
Return (Backgroundthread) O;
}
}

/******************************************************************************************
* Start ()-Starts the custom listen thread
******************************************************************************************/
public void Start () {
Invokelater (New Runnable () {
public void Run () {
Mythread.start ();
}
});

This.entereventdispatcher ();
}
/******************************************************************************************
* Customer Listening thread This is a extention of thread ()
******************************************************************************************/
Class Listenerthread extends Thread {

public void Run () {
Log ("Listenerthread running");
for (int i=0;true;i++) {
try {
Sleep (30000);
catch (Interruptedexception e) {
E.printstacktrace ();
}
Log ("Listenerthread sleep 7 Seconds");

Log ("Listenerthread sleep 1a");

Invokelater (New Runnable () {
public void Run ()
{
Infopopupscreen _screen = new Infopopupscreen ();
Dialog _screen = new Dialog (Dialog.d_ok_cancel, "Close Me", Dialog.d_ok, Bitmap.getpredefinedbitmap (bitmap.question), Manager.vertical_scroll);
Ui.getuiengine (). Pushglobalscreen (_screen, 1, uiengine.global_modal); Global_modal would block
}
} );
}
}
}
/******************************************************************************************/
public static void Loggerinit () {
Eventlogger.register (GUID, AppName, eventlogger.viewer_string);
Log ("loggerinited");
}

public static void log (String value) {
EventLogger
. LogEvent (GUID, Value.getbytes (), eventlogger.always_log);
}

}

/******************************************************************************************/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.