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);
user1120897
  • 272
  • 4
  • 15

1 Answers1

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.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491