Is there any way to have one and only one instance of each activity?

后端 未结 8 1445
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 06:41

I\'m finding that in my application, the user can get quite \'nested\' in the various activities that are opened while the user is using the application.

For example

8条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-08 07:34

    This worked for me.

    Intent intent = new Intent(this, MyActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    startActivity(intent);
    

    If an instance of this Activity already exists, then it will be moved to the front. If an instance does NOT exist, a new instance will be created.

提交回复
热议问题