Search code examples
androidandroid-intentandroid-activityactivity-lifecycle

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


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?


Solution

  • 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;