[英]Android when i close my app then How i can restart my app after x time duration?
我正在使用已经在电视设备上工作的Android应用程序,我希望当我关闭我的应用程序时,如果没有人触摸鼠标或键盘,那么我的应用程序会在x持续时间后自动启动,这是可能的吗?如果是,那么请帮助,非常感谢。
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. 是的,有可能你可以从服务中获得帮助,只需在你的应用程序的Ondestroy()上开始一个timerthread意味着在最后一个活动或你可以在应用程序关闭时执行此操作。 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. 通过在您的服务中使用PendingIntent可以实现。
http://developer.android.com/reference/android/app/PendingIntent.html http://developer.android.com/reference/android/app/PendingIntent.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.