12

I am programming a chat program for android.

I have the contact list as one activity and the chat windows as a second activity. I use startActivity to switch to the chat activity, but the chat activity gets reloaded every time. Therefore the screen gets cleared.

Is there a way to switch to a running activity without having to restart it?

private Intent myIntent = null; 

 if (myIntent == null) myIntent = new Intent(HanasuAndroidActivity.activity, ChatWindow.class); this.startActivity(myIntent); 
1
  • Too complicated. I would use one activity and consider something like ViewFlipper Commented Dec 31, 2011 at 12:45

1 Answer 1

27

Add FLAG_ACTIVITY_REORDER_TO_FRONT to your Intent. That will bring the existing activity instance to the foreground if it exists or create a new one if it does not exist.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.