0

From my activity, I start a new Activity by defining an Intent for it. Then I start the new Activity.

Now suppose in method A this happens :

A {
    /*
     *
     *
     */
    startActivity(i);  // where i is the intent for new Acivity
    /*
     *
     *
     */
}

Now what happens is that statements after start activity are executed even before i starts. I want when I start 'i', the current class pauses the 'i' starts , and afte 'i' finishes, this class resumes from that point ?

Is it possible to do this ?

amalBit
  • 12,041
  • 6
  • 77
  • 94

3 Answers3

0

Write finish(); after startActivity(i); Or call onDestroy() method.

Pratik Dasa
  • 7,439
  • 4
  • 30
  • 44
0

You could call finish() right after your startActivity() call, but that would terminate the first activity. The alternative is to start the new activity with startActivityForResult() and put logic in the first activity to stop doing what it's doing until it gets the results. The results will come as a firing of callback onActivityResult().

This question has a good write-up of an example.

Community
  • 1
  • 1
scottt
  • 8,301
  • 1
  • 31
  • 41
0

The activities live in UI Threat and is impossible stop this threat because Android Kernel protect this.

When you start a new activity with startActivity(i) the old activity appears again if you clic in back button or if you invoque onBackPressed(). And you can overwrite this method to close the actual activity after launch the new, like this :

@Override
public void onBackPressed() {
    Intent i = new Intent(this, ACTIVITYNAME.class );
    startActivity(i);
    this.finish();
}

After you need recall the first activity if you need resume...

And finally, perhaps the best option, you can use startActivityForResult(), here a good example :

How to manage `startActivityForResult` on Android?

Community
  • 1
  • 1
sgarcia
  • 97
  • 4