如何创建一个活动的多个实例? - 重新审视

发布于 2024-10-14 10:53:05 字数 233 浏览 4 评论 0原文

我想使用不同的参数启动同一 (ExpandbleList-)activity 的多个实例,以便在列表中加载不同的数据。这些列表位于 TabActivity 的不同选项卡中。

到目前为止它有效,但是当我更新一个列表中的信息,然后返回到第二个列表并单击其中一个项目(或更改屏幕方向)时,该列表将使用另一个列表中的数据重新填充。

我怎样才能开始活动以便它们不干扰彼此的数据?

I want to start multiple instances of the same (ExpandbleList-)activity using different parameters, so different data is loaded in the lists. These lists are in different tabs of a TabActivity.

So far it works, but when I update the information in one list, then return to the second list and click on one of the items (or change the screen orientation) this list is repopulated with data from the other list.

How can I start the activities so that they don't interfere with each others data?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

生死何惧 2024-10-21 10:53:05

默认情况下,每个 Activity 都是一个新实例。
您是否不小心在此活动的清单中设置了“单顶”?
您是否在 Activity 中设置了不应是静态的静态(共享)成员?
如何实例化“不同”Activity 的个性;通过给予意图额外的东西?

By default, each Activity will be a new instance.
Did you accidently set "single top" in the manifest for this Activity?
Did you set up static (so, shared) members in the Activity which should not be static?
How you instantiate the "different" Activity's personality; by giving Extras to the Intent?

将军与妓 2024-10-21 10:53:05

Activity 不会是一个新实例,这就是它们具有恢复和暂停方法的原因。我试图从广播接收器启动的服务中启动一个新的意图。与主/UI 线程完全不同的线程。除非用户已经运行过,否则工作正常,然后我在尝试创建新意图时遇到以下错误,即使使用标志 Intent.FLAG_ACTIVITY_NEW_TASK 也是如此。 android.view.ViewRoot$CalledFromWrongThreadException:只有创建视图层次结构的原始线程才能触摸其视图。

Activity will not be a new instance, that is why they have the resume and pause methods. I was trying to start a new Intent from a service that was started by a broadcast receiver. A completely different thread than the Main/UI thread. Worked fine unless that had already been run by the user then I got the following error for trying to create a new Intent even with the flag Intent.FLAG_ACTIVITY_NEW_TASK. android.view.ViewRoot$CalledFromWrongThreadException: Only the original thread that created a view heirarchy can touch its views.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文