传递捆绑到活动设置为singletask [英] Passing bundle to activity set as singletask

查看:115
本文介绍了传递捆绑到活动设置为singletask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以,我有一个运行asynchtask偶尔更新,究竟它是(通过字符串)显示在地图上MapActivity。我最初从意图通过这个字符串被第一次创建活动时。然后,如果你点击地图上的可绘之一,它打开了一个新的活动,那么它可以创建一个新的图形页面(同一类),用不同的字符串设置。我的问题是,我只想要的MapView的一个实例能够同时运行。在清单launchmode =singletask:因此我设置机器人。这工作,因为它带来的mapactivity到前面,但有什么办法把它发送一个新的捆绑的意图,以获得它需要的字符串的新环境?我试图从包regetting群众演员,但似乎保留旧的管束,没有传递给它的新意图。我不知道我想要做startActivityForResult由于第二个活动可能会或可能不会想更新原来的活动。

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 string 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.

我希望这是有道理的。我可以张贴code如有必要,但我认为应该解释一下我的情况。

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

推荐答案

当你的活动标记为 singleTask 已在运行一个新的意图发送给它的,<一个href="http://developer.android.com/reference/android/app/Activity.html#onNewIntent%28android.content.Intent%29"><$c$c>onNewIntent会打电话告诉你这件事。

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.

在默认情况下,这个新的意图确实的没有的获取存储在任何方式调用返回后,默认的实现不做任何事情。如果重写 onNewIntent ,您可以处理从那里和/或使用 setIntent 来连接到新的意图直接的临时演员装上新的意图,你的活动,以便将来 getIntent()获得*额外的(...)调用将返回更新的数据。

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.

请注意,有一个特殊情况:如果你的 singleTask 的活动已经推出其任务另一个活动(即没有NEW_TASK标志可嵌入的活动),该活动会当你的活动收到的意图,但意图本身将被直接丢弃的前景。请注意这一点。请参见的开发指南获取更多信息。

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.

这篇关于传递捆绑到活动设置为singletask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆