开发者

Passing bundle to activity set as singletask

So I have a MapActivity that runs an asynchtask that occasionally updates what exactly it's displaying on the map (via a string). I originally pass this string in from the intent when the activity is first created. And then if you click on one of the drawables on the map, it opens a new activity, which can then create a new mapview (same class) with a different st开发者_StackOverflowring setting. The problem I have is that I only want one instance of the mapview to be running at once. Thus I set android:launchmode="singletask" in the manifest. This works in that it brings the mapactivity to the front, but is there any way to send it a new intent bundle to get a new setting for the string it needs? I tried regetting the extras from the bundle, but it seems to retain the old bundle, not the new intent that was passed to it. I'm not sure I want to do startActivityForResult because the 2nd activity may or may not want to update the original activity.

I hope that made sense. I can post code if necessary, but I think that should explain my situation.


When your activity flagged as singleTask is already running and a new Intent is sent to it, onNewIntent will be called to tell you about it.

By default, this new Intent does not get stored in any way after that call returns, and the default implementation does nothing. If you override onNewIntent, you can process the extras attached to the new intent directly from there and/or use setIntent to attach the new intent to your Activity so that future getIntent().get*Extra(...) calls will return the updated data.

Note that there is one special case: if your singleTask activity has launched another activity in its task (i.e. an embeddable activity without the NEW_TASK flag), that activity will come to the foreground when your activity receives an intent, but the intent itself will then be silently dropped. Be careful about that. See the Dev Guide for more info.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜