无论如何要附加到活动堆栈而不执行 StartActivity 吗?

发布于 2024-11-25 22:04:42 字数 374 浏览 0 评论 0原文

我正在解析一个巨大的 xml 以在活动 A 的列表视图中显示标题列表。但是,相同的 xml 还包含需要在不同视图中显示的列表项的详细信息(例如列出邮件主题/查看邮件详细信息场景) )。

在此列表的单击事件中,我不想加载带有捆绑包的新活动、解析相同的 xml 并显示详细视图,而我在活动 A 本身中有所需的数据。

我找到了一种方法来隐藏 XML 中的显示布局,以根据需要执行此操作,但处理后退按钮是一个问题。我可能可以通过捕获后退按钮操作来做到这一点,但想知道是否有更好的解决方案。

就像向 A 广播一个意图(从 A 本身)并以某种方式设法将其添加到活动堆栈中。

请原谅,如果有重复的问题,我搜索时找不到。

顺便说一句,我不想​​用数据库缓存来做解决方案。

I'm parsing a huge xml to display a list of titles in a listview in activity A. However the same xml also has details for a list item which needs to be shown in a different view (like list mail subjects/view mail details scenario).

On click event of this list i dont want to load a new activity with a bundle, parse the same xml and show detailed view, while i have the required data in activity A itself.

I figured out a way to hide show layouts in my XML to do this as required, but handling back button is an issue. I can probably do this by capturing back button action, but want to know whether there is a better solution for this.

Like broadcasting an intent to A (from A itself) and somehow managing to add that to the activity stack.

Excuse if there is a duplicate question, couldnt find one when i searched.

BTW, i dont want to do a solution with a database caching.

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

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

发布评论

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

评论(4

安人多梦 2024-12-02 22:04:42

我会处理后压力。只需在您的活动中使用一个标志来告诉您当前处于哪个视图(因此回到详细视图中会显示概述视图)。

另一种方法是将值保存在 applicationContext 中。比使用数据库更简单的方法。
看看这里的答案:如何在 Android 中声明全局变量?

但我肯定会选择处理背压。我有一个与此类似的解决方案,其中我在布局中使用相同的列表视图,而根据用户所在的详细视图使用不同的适配器。

I would handling the back press. Just use a flag within your activity that tells you in which view you are (so back within the detailed view shows you the overview view).

Another way would be to save the values in your applicationContext. Much easier way to do it than database usage.
Take a look at an answer here: How to declare global variables in Android?

But I would definitely go with handling back presses. I have a solution similar to this where I use the same listview in the layout and instead I use different adapters depending on which detailed view the user is in.

可是我不能没有你 2024-12-02 22:04:42

处理后压力是最简单的方法。

另外,您还可以将要查看的信息作为 Intent extra 传递给第二个活动。

另一种可能性是让本地服务在后台运行,负责加载 XML 并以方便的方式提供对其信息的访问。

您还可以将 XML 内容填充到您自己的 Application 对象中。然而,在某些项目中我对这个选项没有太多的经验。

Handling back press is the easiest way to go.

Else you could also pass the information to view as Intent extra to the second activity.

Another possibility is to have a local service running in the background and in charge of loading your XML and offering access to its information in a convenient way.

You can also stuff the XML content in an Application object of your own. However I have had not so great experience with that option in some projects.

感情旳空白 2024-12-02 22:04:42

我会使用第二个活动。将附加数据(如联系人列表、消息详细信息等)传递给它并显示它。如何将解析后的 XML 保留在内存中由您决定(静态成员?恶心!但它有效)。

现在回到原来的 Activity。您的源 XML 变化很大吗?也许您可以解析它并将所有数据放入数据库中,以便您可以更快地检索必要的(和分层的)数据。这样您就不需要在内存中存储大量数据、重新解析,并且可以更快地执行搜索。

I would use a second activity. Pass additional data (like contact list, message details, etc.) to it and display it. How you keep parsed XML in memory is up to you to decide (static member? yuck! but it works).

Now back to original Activity. Does your source XML change a lot? Maybe you can parse it and put all data into a DB so that you could retrieve necessary (and hierarchical) data quicker. This way you do not need to deal with storing lots of data in memory, re-parsing and you could perform search faster.

烟酒忠诚 2024-12-02 22:04:42

在此列表的单击事件中,我不想加载带有捆绑包的新活动、解析相同的 xml 并显示详细视图,而我在活动 A 本身中有所需的数据。

将解析后的 XML 缓存在静态数据成员中。需要数据的活动首先查看静态数据成员,然后当且仅当该缓存不存在时才开始解析。

IOW,这不是活动问题,而是数据模型问题。更好地处理您的数据模型,您的活动就可以自然地进行。

On click event of this list i dont want to load a new activity with a bundle, parse the same xml and show detailed view, while i have the required data in activity A itself.

Cache the parsed XML in a static data member. Your activities that need the data look at the static data member first, then kick off the parsing if and only if that cache is not there.

IOW, this is not an activity problem, but a data model problem. Do a better job with your data model, and your activities can behave naturally.

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