1.问题
安装apk程序成功后会有两个按钮,打开、完成。打开可以打开安装的程序,此时操作程序。然后按home键再从桌面点击图标打开程序会发现程序从入口重新打开,并不是刚才的运行状态。
2.解决办法
我们在程序入口的activity中检测该activity是不是程序的root Activity。如果不是就可以直接finish此activity,程序会从栈中还原以前的状态。
具体代码如下:
在应用启动的activity的Oncreate方法中添加如下代码即可:
if (!isTaskRoot()) {
// Android launched another instance of the root activity into an existing task
// so just quietly finish and go away, dropping the user back into the activity
// at the top of the stack (ie: the last state of this task)
finish();
return;
}
安装apk程序成功后会有两个按钮,打开、完成。打开可以打开安装的程序,此时操作程序。然后按home键再从桌面点击图标打开程序会发现程序从入口重新打开,并不是刚才的运行状态。
2.解决办法
我们在程序入口的activity中检测该activity是不是程序的root Activity。如果不是就可以直接finish此activity,程序会从栈中还原以前的状态。
具体代码如下:
在应用启动的activity的Oncreate方法中添加如下代码即可:
if (!isTaskRoot()) {
// Android launched another instance of the root activity into an existing task
// so just quietly finish and go away, dropping the user back into the activity
// at the top of the stack (ie: the last state of this task)
finish();
return;
}