Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
314 views
in Technique[技术] by (71.8m points)

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

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...