Back button closes app

Asked

Viewed 2,731 times

2

I have a main Activity (Mainactivity), which contains a list and a Navigationdrawer, when I click the register option is called this screen:

startActivity(new Intent(MainActivity.this, PessoasActivity.class));

And it works normally, but sometimes when I click on the option to return from the actionbar it closes the app, it happens more when I perform the save information operation in the bank. When I click on the option to return from the emulator and tmb on the device and close the app.

My Androidmanifest, Menu Log(Mainactivity) and Register(Personsacitivity):

<activity
        android:name="com.aplicacao.app.MainActivity"
        android:label="@string/app_name"
        android:noHistory="true" >
    </activity>
<activity
        android:name="com.aplicacao.app.PessoasActivity"
        android:label="@string/title_activity_pessoas" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="com.aplicacao.app.MainActivity" />
    </activity>

Imagem do app

  • Thiago, are you sure it’s not because of the attribute noHistory="true" in his MainActivity? With this attribute, the MainActivity doesn’t stay in the BackStack when starting another Activity, causing the problem.

  • I’ll remove and test.

  • It worked, as I do to mark your comment as a response?

  • I’ll create an answer and you can accept it.

1 answer

3


The problem is the use of the attribute noHistory="true". Removing it will solve the problem.

According to the documentation, use this flag is the same as calling finish at the beginning of any Activity with the context of its MainActivity. With that to MainActivity does not remain in the BackStack, and when using the navigation back, either by Back Button or by Home Indicator, to MainActivity will not be restored.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.