I was experimenting with ActivityManager.killBackgroundProcesses in my application and notice something interesting. I hope someone on * can shed some light on this.
我正在我的应用程序中试验ActivityManager.killBackgroundProcesses,并注意到一些有趣的东西。我希望*上的某个人可以对此有所了解。
So if I start an application, for example, youtube, I first see the list of video page, then I click menu->Settings, I will get the settings page. now if I click home button, which will put youtube to background. so far so good. Now if I run ActivityManager.killBackgroundProcesses to kill youtube application (or I use Advanced task killer which I believe using the same API), and when I launch youtube again, I see the setting page, not the default list of video page.
因此,如果我启动一个应用程序,例如youtube,我首先会看到视频页面列表,然后单击menu-> Settings,我将获得设置页面。现在,如果我单击主页按钮,这将把youtube放到后台。到现在为止还挺好。现在,如果我运行ActivityManager.killBackgroundProcesses来杀死youtube应用程序(或者我使用高级任务杀手我相信使用相同的API),当我再次启动youtube时,我会看到设置页面,而不是默认的视频页面列表。
But if instead of doing ActivityManager.killBackgroundProcesses, I go to system settings->manage application->Youtube->Force stop, and when I launch youtube again, I get the list of video page, not the setting page.
但是如果不是做ActivityManager.killBackgroundProcesses,我会进入系统设置 - >管理应用程序 - > Youtube->强制停止,当我再次启动youtube时,我得到的是视频页面列表,而不是设置页面。
So it seems that ActivityManager.killBackgroundProcesses is different from force stop as it still remembers the last task/page it was on before it was put to background, whereas force stop gives you a fresh start.
所以似乎ActivityManager.killBackgroundProcesses与强制停止不同,因为它仍然会记住它在放到后台之前所处的最后一个任务/页面,而强制停止会给你一个新的开始。
Anyone has good explanation for it? Is it possible in my code to do "force stop" to get a fresh start of the application?
任何人都有很好的解释吗?是否可以在我的代码中执行“强制停止”以重新启动应用程序?
Many thanks!
2 个解决方案
#1
1
Well, I am not sure how use it exactly as I have never try before with apps other than mine, but mayby it would help - think about using: android.os.Process.killProcess(android.os.Process.myPid());
好吧,我不确定如何使用它,因为我以前从未尝试使用除我以外的应用程序,但可能会有所帮助 - 考虑使用:android.os.Process.killProcess(android.os.Process.myPid()) ;
And about your question why system can stop and you can't. The truth is that system can more. More specyfic, when you press force stop button system is sending kill signal (signal 9) to process with given pid.
关于你的问题,为什么系统可以停止,你不能。事实是系统可以更多。更具规格性,当您按下强制停止按钮系统时,发送终止信号(信号9)以使用给定的pid进行处理。
This is why I think the above function should help, because it is sending almost, if not exactly this same, signal.
这就是为什么我认为上述功能应该有所帮助,因为它几乎发送信号,如果不是完全相同的话。
Hope it will help.
希望它会有所帮助。
#2
0
Recording to Android OS security system your app can't just kill another activity. You can send request to system and then it will do all required stuff for you, if it possible.
记录到Android操作系统安全系统,您的应用程序不能只杀死其他活动。您可以向系统发送请求,然后它会为您执行所有必需的操作,如果可能的话。
Settings is system application, that's why it has more access than your app.
设置是系统应用程序,这就是为什么它具有比您的应用程序更多的访问权限。
So, looks like OS not allowed you to kill apps. Not sure, but try to check your app permisionns - maybe solution is there.
所以,看起来操作系统不允许你杀死应用程序。不确定,但尝试检查你的应用程序permisionns - 也许解决方案是存在的。
#1
1
Well, I am not sure how use it exactly as I have never try before with apps other than mine, but mayby it would help - think about using: android.os.Process.killProcess(android.os.Process.myPid());
好吧,我不确定如何使用它,因为我以前从未尝试使用除我以外的应用程序,但可能会有所帮助 - 考虑使用:android.os.Process.killProcess(android.os.Process.myPid()) ;
And about your question why system can stop and you can't. The truth is that system can more. More specyfic, when you press force stop button system is sending kill signal (signal 9) to process with given pid.
关于你的问题,为什么系统可以停止,你不能。事实是系统可以更多。更具规格性,当您按下强制停止按钮系统时,发送终止信号(信号9)以使用给定的pid进行处理。
This is why I think the above function should help, because it is sending almost, if not exactly this same, signal.
这就是为什么我认为上述功能应该有所帮助,因为它几乎发送信号,如果不是完全相同的话。
Hope it will help.
希望它会有所帮助。
#2
0
Recording to Android OS security system your app can't just kill another activity. You can send request to system and then it will do all required stuff for you, if it possible.
记录到Android操作系统安全系统,您的应用程序不能只杀死其他活动。您可以向系统发送请求,然后它会为您执行所有必需的操作,如果可能的话。
Settings is system application, that's why it has more access than your app.
设置是系统应用程序,这就是为什么它具有比您的应用程序更多的访问权限。
So, looks like OS not allowed you to kill apps. Not sure, but try to check your app permisionns - maybe solution is there.
所以,看起来操作系统不允许你杀死应用程序。不确定,但尝试检查你的应用程序permisionns - 也许解决方案是存在的。