PDA

View Full Version : How to run my application in background?


siqiabc
10-30-2007, 09:32 PM
How to run my application in background?

streamh
10-30-2007, 10:09 PM
/*
* guiLessApplication.java
*
* ?<your company here>, 2003-2005
* Confidential and proprietary.
*/

package GUILessApp;

import net.rim.device.api.ui.*;
import net.rim.device.api.ui.component.*;
import net.rim.device.api.ui.container.*;
import net.rim.device.api.system.*;

public final class GUILessApp extends Application
{
private BackGroundApp backGroundApp;
public static void main(String[] args)
{
GUILessApp theApp = new GUILessApp();
theApp.enterEventDispatcher();
}

public GUILessApp()
{
//Creates and starts a new BackGroundApp thread.

backGroundApp = new BackGroundApp();
backGroundApp.start();
}

//The thread that will run in the background.
private class BackGroundApp extends Thread
{
boolean stopThread = false;
public synchronized void stop()
{
stopThread = true;
}

public void run()
{
int n = 0;
while (!stopThread)
{
//You would perform your processing here.
//This sample just prints out a line
//to the BlackBerry JDE Output Window

System.out.println("Application is running" + n + "th times!");
n++;

//Sleep for 5 seconds to prevent the
//application from running out of control
try
{
sleep(5000);
}
catch (Exception e)
{
//Exception handling would go here.
}
}
}
}
//Stop the thread on exit.
protected void onExit()
{
backGroundApp.stop();
}
}

siqiabc
10-31-2007, 01:29 AM
thank you!

genvej
10-31-2007, 05:17 AM
Another way to do it is to edit the properties of your project and simply tick

system module

auto-run on startup