Mika
Mika

Reputation: 5845

Back button calls onDestroy() on parent

Why does the back tubbon call onDestroy() on the parent?

I have the following scenario:

  1. Activity A that opens Activity B via an intent

    Intent intent = new Intent(parent.getContext(), activityB.class);
    intent.putExtra(STATE_REST, gson.toJson(myObject));
    startActivity(intent);
    
  2. When I click on back on activity B (and only then) activity A fires onDestroy() followed by onCreate().

Manifest:

Activity A

<activity
    android:name=".activities.MainActivity"
    android:configChanges="orientation"
    android:screenOrientation="portrait"
    android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Activity B

<activity
    android:name=".activities.MenuActivity"
    android:configChanges="orientation"
    android:screenOrientation="portrait"
    android:label="@string/menu_title"
    android:parentActivityName=".activities.MainActivity">
</activity>

Upvotes: 1

Views: 1300

Answers (1)

Med Besbes
Med Besbes

Reputation: 2021

your problem seems to be resolved in the flowing link: Why is onDestroy always called when returning to parent activity?

Good luck.

Upvotes: 3

Related Questions