简体   繁体   中英

Android when i close my app then How i can restart my app after x time duration?

我正在使用已经在电视设备上工作的Android应用程序,我希望当我关闭我的应用程序时,如果没有人触摸鼠标或键盘,那么我的应用程序会在x持续时间后自动启动,这是可能的吗?如果是,那么请帮助,非常感谢。

Yes, it is possible, in a Android Service you check if your app is running (check this ) if not, you can launch your app. For check user interaction check this

Yes it is possible U can take help from service just start one timerthread on Ondestroy() of your app means On last activity or u can perform this action on close of your app. Check with ideal state from thread if any broadcast from mouse or keyboard u will get then reset your timer thread according to it. When ever your timer thread reach at your time just start activity programmatic like

 Intent i = Context.getPackageManager().getLaunchIntentForPackage(Context.getPackageName() );
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                i.addCategory(Intent.CATEGORY_HOME);
                i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                Context.startActivity(i);

Its Possible by using PendingIntent in your service.

http://developer.android.com/reference/android/app/PendingIntent.html

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