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
Developer
nkarasev
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified
Accepted Solution

Using FLAG_AUTO_RESTART

Hi,

 

this flag exists in ApplicationDescriptor however I cannot see how to set this flag to an application other than running it from within another application (i.e. programmatically).

 

Project in Eclipse does not have any relevant settings. Maybe it is possible through modifying XML/JDP descriptor directly ? But then the JDP file is rewritten every time.

 

Any ideas?

 

Thanks,

Nikolay

 

Developer
swiebertje
Posts: 64
Registered: ‎05-09-2009
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

I would like to know this as well, i'm trying to accomplish an auto restart feature after the user invoked some kind of re-initialize action.
Developer
nkarasev
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

As you can see - I got nothing so far.

 

Looks like this is unavailable as app standard config option - you'll have to start this app programmatically from within another app to get this working.

 

Developer
peter_strange
Posts: 19,610
Registered: ‎07-14-2008
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

Does this help?

 

How To - Allow an application to restart itself
Article Number: DB-00551
http://www.blackberry.com/knowledgecenterpublic/livelink.exe/fetch/2000/348583/800332/800620/How_To_...

Developer
nkarasev
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

This is a very interesting idea, indeed!

Will try and let you all know

 

Developer
nkarasev
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

This is an interesting approach, however for some reason setting the flag ApplicationDescriptor.FLAG_AUTO_RESTART did not work for the restarted app. Strange ...
Developer
nkarasev
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

All right, I confess: it was after midnight and I forgot to add extra argument in API call, hence did not make the test work.

 

So this IS THE WAY to restart app once and then let system care for subsequent restart if app exits !!!

Problem solved.

 

Here is the code of you main function, everything else will be your normal UI Application:

 

    public static void main(String[] args)

    {

        if (args.length == 0)

        {

            // need autorestart

            ApplicationDescriptor descr = ApplicationDescriptor.currentApplicationDescriptor();

            ApplicationDescriptor newDescr = new ApplicationDescriptor(descr, descr.getName(), new String[] { "auto" },

                    descr.getIcon(), descr.getPosition(), descr.getNameResourceBundle(), descr.getNameResourceId(),

                    ApplicationDescriptor.FLAG_AUTO_RESTART);

            ApplicationManager.getApplicationManager().scheduleApplication(newDescr,

                    System.currentTimeMillis() + 60001, true);

            System.exit(0);

            return;

        }

        AutoRestartApp app = new AutoRestartApp();

        app.enterEventDispatcher();

    }

 

Developer
Posts: 1,474
Registered: ‎04-14-2009
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

Interesting! Do you happen to know how to "cancel" the auto-restart flag? Say you use the flag for auto-restarting the app if it crashes, but, if the user manually shuts down the application, the application should no longer start automatically until the user starts it again...
Developer
swiebertje
Posts: 64
Registered: ‎05-09-2009
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

The only problem i found with that code is it does not start the application immediately, it could take up to a minute. I was looking for something to restart the application immediately after closing.
Developer
nkarasev
Posts: 23
Registered: ‎08-06-2008
My Device: Not Specified

Re: Using FLAG_AUTO_RESTART

I neither know how to "cancel" autorestart feature nor I know how to run the app immediately.

It is strange that BB has added some interesting features but did not provided good support for them. To my mind - the auto-restart feature is actually useless. Imagine you created an application with start at system startup and autorestart - it will never, ever shut down ! ...

Bummer.