在停止使用startActivity启动的应用时遇到一些问题。我是这样开始的:
Intent theApp = new Intent();
theApp = getPackageManager().getLaunchIntentForPackage(thePackageName);
theApp.addCategory(Intent.CATEGORY_LAUNCHER);
theApp.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getApplicationContext().startActivity(theApp);
运行一段时间之后,我试图像这样阻止它:
if(stopService(theApp))
Log.d(TAG,"Stopped app successfully!");
else
Log.d(TAG,"Failed to stop the app!");
为什么这不起作用的任何想法?在此先感谢您的帮助
答案 0 :(得分:0)
您似乎正在开展活动。并且您正试图停止服务,这将无法正常工作。 如果要停止整个应用程序。你可以使用System.exit()。
答案 1 :(得分:0)
这不起作用的原因是您尝试使用旨在停止服务的方法来停止活动。
您可以尝试对新创建的活动进行静态引用,然后在希望结束时调用finish()。
或者你可以尝试这种方法:How to stop an activity in android using intent?
答案 2 :(得分:0)
按packegename搜索killBackgroundProcess(pid)或Kill进程。