从前台启动应用程序后如何恢复列表视图和其他视图的最后值?

发布于 2024-09-27 03:58:22 字数 107 浏览 0 评论 0原文

当我单击主页按钮然后返回到我的应用程序时,它不会显示列表视图或任何其他视图上的最后一个值,它看起来与我启动应用程序时相同。我相信这可以通过 onResume 和 onPause 来完成但我找不到如何。

When i click home button and then come back to to my application it doesn't show the last values on the listview or any other view it just look same with when i started the application.I believe it is can be done with onResume and onPause but i couldn't find how .

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

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

发布评论

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

评论(3

终弃我 2024-10-04 03:58:22

有多种方法可以实现此目的:

  1. SQLite 数据库
  2. 将数据作为文件存储在 SD 卡上。
  3. 活动的共享首选项。
  4. 作为 Application 类中的静态变量。

在 Android 活动之间切换

不久前曾问过同样的问题。

Multiple ways to do this:

  1. An SQLite database
  2. Store the data as a file on the SD card.
  3. SharedPreferences for the activity.
  4. As a static variable in the Application class.

Switching between Android activities

Had asked the same question some time back.

中二柚 2024-10-04 03:58:22

您可以在 onPause 中将所有值存储在 SharedPreferences 中,然后在 onResume 中再次加载它们并使用该数据填充您的视图。

You can store all values in SharedPreferences in onPause, and then load them again in onResume and populate your views using that data.

独守阴晴ぅ圆缺 2024-10-04 03:58:22

要全面了解,请在此处阅读有关 Activity 生命周期和保存 Activity 状态的信息。

To get a full understanding, read about activity lifecycles and saving activity state here.

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