Skip to content Skip to sidebar Skip to footer

Resume Previous Activity Onbackpressed

I have two activities in my project. A and B, when user click a button in activity A , i am opening activity B A --- > B When user click back button ,application returns the act

Solution 1:

Try this:

In your manifest,

<activityandroid:label="@string/app_name"android:name="ActivityB"android:launchMode="singleTop" >

And don't call finish() on activity B while going back. So it should resume the old instance of running activity B.

Reference

So now a new instance of a "singleTop" activity will only be created to handle a new intent if there is no any instance already. However, if the target task already has an existing instance of the activity at the top of its stack, that instance will receive the new intent (in an onNewIntent() call); a new instance is not created.

Edit:

This code works for me:

In MainActivity:

//Go button's onClickpublicvoidgoToSecond(View v){

    Intent go = newIntent(this, ChildActivity.class);
    startActivity(go);
}

//Resume button's onClickpublicvoidresumeSecond(View v){

    Intent go = newIntent(this, ChildActivity.class);
    startActivity(go);
}

In ChildActivity:

//Back button's onClickpublicvoidgoback(View v){
    // onBackPressed();
    Intent go = newIntent(this, MainActivity.class);
    startActivity(go);
}

And in manifest:

<activityandroid:name="com.example.testingproj.ChildActivity"android:label="@string/app_name"android:launchMode="singleTask" >

At this time, ChildActivity's onCreate() is called just when I click on button Go. If I click on Resume button, its not recreated.

Post a Comment for "Resume Previous Activity Onbackpressed"