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 can reach the single instance aim, but it won't update the view of the activity.
This activity is launched by startActivityForResult
, and we send the URI with the intent to the activity.
Let's discuss with this certain case:
gallery - lauch this activity with imageA.
camera - lauch this activity with imageB.
My request is not to destroy the old activity, but the activity that just received the new intent infomation should refresh the view.
I found a new method, onNewIntent
. This method can refresh the intent before resume. I will try it.
android:launchMode= "singleInstance" /> ;this method will start a new task with the activity. A "singleInstance" activity, on the other hand, permits no other activities to be part of its task. It's the only activity in the task. Thus, use android:launchMode="singleTask".
singleInstance This is very special launch mode and only used in the applications that has only one activity. It is similar to singleTask except that no other activities will be created in the same task. Any other activity started from here will create in a new task.
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" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With