Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Close application in Background after certain interval of time in Blackberry

I wish to Close application in Background after certain interval of time. Basically I wish to maintain user session.The session can last upto 5 to 10 minutes.

like image 961
Shishir Shetty Avatar asked Feb 04 '26 13:02

Shishir Shetty


1 Answers

// to close the application after some time if it is in background.
// you have to override the following method. Pass the time in seconds 
// after which you want to close the application.

    public void deactivate(){       
        new CloseAppInBackground(time duration);        
    }


    public class CloseAppInBackground {
        Timer timer;

        public CloseAppInBackground(int seconds) {
            timer = new Timer();
            timer.schedule(new CloseBackgroundAppTask(), seconds*1000);
        }

        class CloseBackgroundAppTask extends TimerTask {
            public void run() {
                // check whether the application is in foreground or not 
                if(!UiApplication.getUiApplication().isForeground())
                    System.exit(0); // exit the application.

                    timer.cancel(); //Terminate the timer thread
                 }
        }
    }
like image 163
Ritesh Gune Avatar answered Feb 06 '26 01:02

Ritesh Gune



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!