简体   繁体   中英

Restart android application after a time

I need to restart my android after a time. My application is a slideshow with images. The user close the application by home button or by back button. I need to restart the application after a time (a few minutes after the lost user's touch on the device - like the screen ssaver works). Is it possible to do this? Can anyone help me how can I do this?

I'm not sure it's a very good idea. If your user wants to quit your app, why should you bring it to the front?

However, I think you can achieve that using a background service , which launch an Intent after a certain time.

Imho the best solution is Alarm Manager. http://developer.android.com/reference/android/app/AlarmManager.html sample:

long nexttime = (new Date()).getTime() + 60L*60L*1000L;//one hour after.

    AlarmManager am=(AlarmManager)getSystemService(Activity.ALARM_SERVICE);
            Intent intent = new Intent(this, MyService.class);
            intent.putExtra(SomeExtras, false);//for instance
            PendingIntent pi = PendingIntent.getService(this, 12345, intent, PendingIntent.FLAG_CANCEL_CURRENT);
            am.set(AlarmManager.RTC,nexttime, pi);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM