[英]Kill android application after X time
I have been searching around for a way to kill my application after the user put it in the background for at least 30min. 在用户将其放在后台至少30分钟后,我一直在寻找一种杀死我的应用程序的方法。
So far what i have found things like : 到目前为止,我发现了以下内容:
getActivity().finish();
Process.killProcess(Process.myPid());
System.exit(1);
private void stopServices() {
final ActivityManager activityManager = SystemServices.getActivityManager(context);
final List<ActivityManager.RunningServiceInfo> runningServices = activityManager.getRunningServices(Integer.MAX_VALUE);
final int pid = Process.myPid();
for (ActivityManager.RunningServiceInfo serviceInfo : runningServices) {
if (serviceInfo.pid == pid && !SenderService.class.getName().equals(serviceInfo.service.getClassName())) {
try {
final Intent intent = new Intent();
intent.setComponent(serviceInfo.service);
context.stopService(intent);
} catch (SecurityException e) {
// handle exception
}
}
}
}
Pretty much what i have figered so far is taht after API 21 use 到目前为止,我所了解的几乎是API 21使用后的结果
finishAndRemoveTask();
before that use this.finishAffinity();
在此之前使用this.finishAffinity();
But how to start timer once the app is put in the background
for X time and then call the app kill method. 但是,一旦应用程序在background
放置X次后如何启动计时器,然后调用应用程序kill方法。
So what I understand that you need 2 things: 因此,据我了解,您需要两件事:
So here are 2 links for this questions: 因此,这里有2个有关此问题的链接:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.