问题
Similar to this question, I added no history flag to my login activity. in another side, i have a button in login activity to show wireless setting. When i press back on wireless setting intent, application closed!
How can i have no history flag and prevent application from closing?
回答1:
When you launch another activity your login activity is finished using the no history flag. You either have to move your wireless setting to another activity or calling finish in the login activity when launching other activity beside wireless setting. In case you keep the wireless button in your login you cannot use no history. You have to set a flag to indicate if setting wireless setting is being launched and in onStop called finish() if this flag is false.
In your Login activity
private boolean mShowSetting;
In onStop()
if (!mShowSetting)
{
finish();
}
In the method where you start the activity to show setting
mShowSetting = true;
and in your onResume you have to set
mShowSetting = false;
回答2:
UPDATE: This solution does NOT work! I don't know why?
Add launchMode to login activity in manifest like this:
<activity android:name="Login" android:noHistory="true" android:launchMode="singleTop" />
If an instance of the activity already exists at the top of the target task, the system routes the intent to that instance through a call to its onNewIntent() method, rather than creating a new instance of the activity.
https://developer.android.com/guide/topics/manifest/activity-element.html
来源:https://stackoverflow.com/questions/24698907/application-closing-on-back-button-after-viewing-wireless-setting-by-intent-acti