0

I have open activities like this

Activity-A(Get the User Personal Details) -->

Activity-B(Getting the User Contact Info) -->

Activity-C(Getting the User Credit Card Details) -->

Activity-D(Credit Card Verification)

Now from the Activity-D, I need to move to the Activity-B wihtout loosing user entered data on the Activity-B

I have tried finish() menthod on Activity-D But It fails.

I have open every activity using the following method. Example from Activtiy-A to Activty-B

 Intent intent_B = new Intent(getApplicationContext(), ActivityB.class)
startActivity(intent_B);

How to I resume the Activity-B from Activity-D

nifCody
  • 2,394
  • 3
  • 34
  • 54
  • 1
    use saveInstanceState to handle these events.. Read documentation here.. https://developer.android.com/training/basics/activity-lifecycle/recreating.html – Queendevelopers Nov 29 '16 at 16:14
  • Just call the activity b from activity d again – Panda Nov 29 '16 at 16:14
  • @M.S.P how do i call activtiy B from activity D. It creates as new Activity without any data I have entered – nifCody Nov 29 '16 at 16:16
  • Pass your data using the key value pair or Buffer. But even I would suggest you to go with saveinstancestate – Panda Nov 29 '16 at 16:17

4 Answers4

1
  1. Store/Restore whole required data of activity B to savedInstanceState.

  2. Start activity B from activity D with Intent.FLAG_ACTIVITY_CLEAR_TOP

This lead to behavior you exactly need:

  • activity C & D is cleared from backstack
  • previously created activity B is opened
  • User can return from activity D to activity C by clicking back button
  • Also we prevent data from loosing in case removing invisible activities from memory by system
Community
  • 1
  • 1
Beloo
  • 9,723
  • 7
  • 40
  • 71
1

Simple solutions for your problem.

you Should call finish() before navigate to Activity D.

Intent intent_D = new Intent(getApplicationContext(), ActivityD.class)
startActivity(intent_D);
finish();

this will finish Activity C and Activity A and B are still in background. so when you Click Backpress or call finish() on Activity D, you will be navigate on Activity B and your data will be available without any extra effort.

Nishchal Sharma
  • 1,070
  • 9
  • 16
0

Best way to do this would be to use Either static variables or Singleton class. Please find singleton explained here: link

As for static variables, please look here: link

Vulovic Vukasin
  • 1,540
  • 2
  • 21
  • 30
-1

Here's

IN Activity 1 ::

int REQ_INT=888;
Intent intent_B = new Intent(getApplicationContext(), ActivityB.class)
startActivityForResult(intent_B,REQ_INT);
 @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (resultCode == RESULT_OK)
            switch (requestCode) {
                case REQ_INT: 
                 //DO your stuff here after getting in this activity again..
                 break;
            }
    }

In Activity 2::

After finishing the task for that activity .

Just

setResult(RESULT_OK);
finish();

you can pass the data to that activity with intent..

Or go see these link Link1 Link 2

Anil Prajapati
  • 457
  • 3
  • 10