Issue
I'm relatively new to the Android world. I have an activity (PartyActivity) showing some info about a party. Pressing the button "Edit" it starts a new activity (EditPartyActivity) that allows the user to edit the info of the party. EditPartyActivity has an Up Navigation Button on his Action Bar that allows the user to go back to PartyActivity and here is my problem. When I go back to PartyActivity it is recreated from zero instead of resume it how it was. I would that when PartyActivity launches EditPartyActivity it stops saving his state and when I go back to PartyActivity from EditPartyActivity it not starts a new instance of PartyActivity, but it resumes the old PartyActivity that launched it. This is my code:
AndroidManifest
<activity
android:name=".EditPartyActivity"
android:screenOrientation="portrait"
android:parentActivityName=".PartyActivity">
<!-- Parent activity meta-data to support 4.0 and lower -->
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".PartyActivity" />
</activity>
PartyActivity
Intent i = new Intent(PartyActivity.this, EditPartyActivity.class);
startActivity(i);
There is not "finish()" after "startActivity(i)".
Solution
By specifying the parent activity name in the manifest it will always set the parent activity to be restarted. If you don't want this you have the option to provide a different functionality for the up button as below. Ideally you want to do this in a base activity so all your activities who need a similar back behavior do the same instead of placing below code in every activity.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case android.R.id.home://user clicked up button
finish();
return true;
}
return super.onOptionsItemSelected(item);
}
Answered By - HaroldSer
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.