Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - switch to activity without restarting it

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);
like image 883
user1120897 Avatar asked Dec 31 '11 12:12

user1120897


1 Answers

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.

like image 107
CommonsWare Avatar answered Nov 15 '22 21:11

CommonsWare