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

前端 未结 2 1471
萌比男神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:01

    You can have an Activity with a manifest attribute of singleInstance. As soon as the activity is relaunched , onResume gets called. You can update the view with the new image and invalidate the older View.

    <activity ..
          android:launchMode= "singleInstance" />
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题