user2784307
user2784307

Reputation: 41

Activity calls another activity and must resume again after another activity finishes

I'm new to Android. My problem is:

  1. Activity A calls activity B in the middle of its execution
  2. Activity B must start and complete its execution
  3. Only then activity A must resume (not restart)

Activity A has a loop. Somewhere in the middle of loop, Activity B is called, and once B finishes, A should resume the loop from where it left off.

I tried to code this, but what happens right now is that Activity A calls B, but B is not entered, then A resumes the loop and again calls B.

Essentially, the calls to B are stacked and once the loop in A completes, one by one the calls to B in stack are executed, so finally the first call to B is executed last in a last-in first-out order. I just want to execute B once, at the appropriate time.

Can anyone help me?

Upvotes: 0

Views: 1102

Answers (3)

Mario Stoilov
Mario Stoilov

Reputation: 3447

Take a look at Starting Activity for result. You can start Activity B for some result, and when Activity B finishes, the onActivityResult method of Activity A will be called and you can set it to continue/start work there.

EDIT
Based on your updated question you can try:

  1. Create a method in Activity A which starts a loop
  2. When you decide you want to call Activity B
    2.1 Exit the loop, and save to where the loop is
    2.2 Start Activity B for result
  3. When Activity B finishes and returns you some kind of result, you will restart the loop (form the point you saved in step 2.1) in Activity A

Upvotes: 0

Philip Sheard
Philip Sheard

Reputation: 5815

You are using the wrong design paradigm for your app. You should not start another activity like that. Keep the code on separate modules by all means, but do not start another activity just to transfer control.

Upvotes: 1

rachit
rachit

Reputation: 1996

Your activity will resume, when calling the Acticity B, don't finish Activity A. If you need to write some code when it resumes. you can do that by overriding onResume method of Activity A.

Upvotes: 0

Related Questions