Android的保持活动的背景 [英] Android Keep Activity in Background

查看:79
本文介绍了Android的保持活动的背景的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个活动的应用程序 - MainActivity,CpuActivity,等我CpuActivity有有 savedInstanceState 片段。每当我preSS背部或导航到MainActivity的CpuActivity被杀害和 savedInstanceState 丢失。是否有可能继续保存的数据/活动的背景或者我需要使用某种形式的临时存储(如共享preferences)?

I have a multiple activity app - MainActivity, CpuActivity, etc. My CpuActivity has fragments that have savedInstanceState. Whenever I press back or navigate up to the MainActivity the CpuActivity is killed and the savedInstanceState is lost. Is it possible to keep the saved data/activity in the background or do I need to use some kind of temporary storage (e.g. SharedPreferences)?

中的数据只能存放,直到整个应用程序被杀害,因此没有任何系统比共享preferences好?

The data should only be stored until the whole app is killed, so is there any system better than SharedPreferences?

推荐答案

一个简单的解决方案是将数据存储在您的应用程序实例。要做到这一点,你必须指定在清单中的应用程序实现(安卓应用程序中的变量名称属性)。您可以使用 getApplication()方法

A simple solution is to store the data in your application instance. To do that you have to specify an Application implementation in the manifest (the android:name attribute in the application tag). You can get the application using the getApplication() method.

这篇关于Android的保持活动的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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