Application closing on back button after viewing wireless setting by Intent.ACTION_WIRELESS_SETTING

▼魔方 西西 提交于 2019-12-11 09:28:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!