Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
New Developer
hideoaki
Posts: 9
Registered: ‎07-31-2009
My Device: Not Specified
Accepted Solution

The app never auto-run on startup

Hi All,

 

I have searched all the forums and tried all the code to make my application auto-run on startup. Unfortunately, when I tested my code on the real device. The application never auto-run when the device start (I tested by remove battery and put it in again.).

Please see my code in below, I have created 2 projects for testing the function. But they're not working.

 

1. loop until app not in startup

public class AutoStartTest extends UiApplication {
	public static void main(String[] args) {
		new AutoStartTest().enterEventDispatcher(); // GUI
	}

	AutoStartTest() {
		try {
			// check if still in startup
			ApplicationManager app = ApplicationManager.getApplicationManager();
			boolean keepGoing = true;
			while (keepGoing) {
				if (app.inStartup()) {
					Thread.sleep(1000);
				} else {
					keepGoing = false;
				}
			}
			
			// Push a new GUI screen.
			DummyScreen screen = new DummyScreen();
			pushScreen(screen);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	// Simple GUI screen from which to create an Invocation.
	final class DummyScreen extends MainScreen {
		DummyScreen() {
			setTitle(new LabelField("Autostart test 2", Field.FIELD_HCENTER));
		}
	}

 2. use system listener

public class AutoStartTest extends UiApplication implements SystemListener {

	public static void main(String[] args) {

		AutoStartTest appInstance = new AutoStartTest();

		// If system startup is still in progress when this
		// application is run.
		if (ApplicationManager.getApplicationManager().inStartup()) {
			appInstance.addSystemListener(appInstance);
		} else {
			appInstance.doStartupWorkLater();
		}
		appInstance.enterEventDispatcher();
	}

	// constructs
	AutoStartTest() {

	}

	private void doStartupWorkLater() {
		
		invokeLater(new Runnable() {
			public void run() {
				doStartupWork();
			}
		});
	}

	private void doStartupWork() {
		// Push a new GUI screen.
		DummyScreen screen = new DummyScreen();
		pushScreen(screen);
	}

	//
	// SystemListener
	//

	/** @see SystemListener#powerUp() */
	public void powerUp() {
		removeSystemListener(this);
		doStartupWorkLater();
	}

	final class DummyScreen extends MainScreen {
		DummyScreen() {
			setTitle(new LabelField("Autorstarttest 3 ", Field.FIELD_HCENTER));
			
		}
	}

 This is the settingset.jpg


I also attached the project in attached file. But in the project I tried to create a thread to send http get and log in the server side. But it seemed that the app did not start too.

Please use plain text.
New Developer
hideoaki
Posts: 9
Registered: ‎07-31-2009
My Device: Not Specified

Re: The app never auto-run on startup

Anybody... please help :Angel:

Please use plain text.
Super Contributor
Achin
Posts: 425
Registered: ‎01-02-2013
My Device: BOLD 9900
My Carrier: sdvsdvsd

Re: The app never auto-run on startup

Please use plain text.
Developer
simon_hain
Posts: 16,113
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: The app never auto-run on startup

i would suggest that you put some logging in and check if it is executed properly
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Please use plain text.
New Developer
hideoaki
Posts: 9
Registered: ‎07-31-2009
My Device: Not Specified

Re: The app never auto-run on startup

Thanks. This method works fine. You save my life!!

Please use plain text.