Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I 'navigate' to an activity that's already running?

Newbie question... So I have two activities, Cherry and Apple, and each one has a button on it to go to the other one. So back and forth.

In class "Cherry" I say this:

intent = new Intent(Cherry.this, Apple.class)
startActivity(intent);

Meaning that it should go to the Apple. There's similar code in the Apple activity.

What I think I am seeing is, is that each time when I startActivity Apple for example, it's starting a new instance of it instead of just reactivating Apple. I've scoured the doc and can't find the flag or other call that would do what I want.

Any tips would be appreciated!

-- Pito

like image 826
pitosalas Avatar asked Mar 27 '11 14:03

pitosalas


1 Answers

What about FLAG_ACTIVITY_REORDER_TO_FRONT?

FLAG_ACTIVITY_CLEAR_TOP is also quite useful, finishing activities on the back stack until the target activity is reached.

To be clear, your activity may be restarted even if using the flags above. This would happen if your activity were destroyed in an attempt to free memory. In other words, you still need to make sure your activity can handle being restarted, taking the proper precautions in onPause and onSaveInstanceState.

like image 190
Matthew Willis Avatar answered Sep 22 '22 23:09

Matthew Willis