How to keep a single activity instance but be able to update the view?

前端 未结 2 1470
萌比男神i
萌比男神i 2020-12-13 13:14

In my situation, there is one case in which I need to make sure the activity only runs one at a time.

I found if I set the LauchMode of the activity, I

2条回答
  •  执笔经年
    2020-12-13 14:06

    In your manifest, use android:launchMode="singleTask" instead of android:launchMode="singleInstance". Using singleInstance only returns to the existing instance if it is at the top of the stack. singleTask, on the other hand, return to the existing instance of the activity, as it is always at the root of the task.

    Then, when your instance is launched, override onNewIntent to update your UI according to the new intent.

    Refer to the Andorid documentation for details.

提交回复
热议问题