参见英文答案 > How to kill an application with all its activities? 6个
如何在单击中终止整个应用程序..完成()不起作用?它重定向到以前的活动…请指导我.
public void onClick(View arg0) {
// TODO Auto-generated method stub
WallpaperManager wp = WallpaperManager
.getInstance(getApplicationContext());
try {
Display d = ((WindowManager) getSystemService(Context.WINDOW_SERVICE))
.getDefaultDisplay();
int width = d.getWidth();
int height = d.getHeight();
wp.setBitmap(b1);
} catch (IOException e) {
Log.e("error", "Cannot set image as wallpaper", e);
}
finish();
}
解决方法:
如果堆栈上有多个活动,System.exit()不会终止您的应用程序
使用android.os.Process.killProcess(android.os.Process.myPid());这条路.
样品
public void onBackPressed() {
android.os.Process.killProcess(android.os.Process.myPid());
super.onBackPressed();
}
我希望这能帮到您.
标签:android,process,kill
来源: https://codeday.me/bug/20191006/1860759.html