[英]Android how to keep static data on application relaunch?
I am having an abstract class having all static objects and function to store some globel data of the application during the execution session. 我有一个抽象类,其中包含所有静态对象和函数,用于在执行会话期间存储应用程序的某些全局数据。
All data reset to null once I relaunch the application in ICS and above version with Systems's setting ALWAYS_FINISH_ACTIVITIES is set as true. 在系统设置为ALWAYS_FINISH_ACTIVITIES的ICS和更高版本中重新启动应用程序后,所有数据都将重置为null。
Whats the better way to mainitan data on application relaunch? 在应用程序重新启动时维护数据的更好方法是什么?
Regards, 问候,
Android IT Android IT
Editing my question: I know that Sharepreference can be a better option but I dont want to store data for multiple sessions of the application and data I am storing is huge. 编辑我的问题:我知道Sharepreference可能是一个更好的选择,但是我不想为应用程序的多个会话存储数据,并且我存储的数据非常庞大。 Regards, Android IT 此致Android IT
Each Android app is running in a dependent process. 每个Android应用程序都在一个依赖的进程中运行。 When an app become background and system need memory, the app's process may be killed by system. 当应用程序变为后台并且系统需要内存时,该应用程序的进程可能会被系统杀死。 In this situation, when app relaunch, static objects will lost. 在这种情况下,应用重新启动时,静态对象将丢失。
I think use SharedPreference to maintain data is a better way. 我认为使用SharedPreference维护数据是一种更好的方法。
您可以使用SharedPreferences
http://developer.android.com/reference/android/content/SharedPreferences.html来存储数据
将数据存储在本地存储上似乎是合适的: http : //developer.android.com/training/basics/data-storage/index.html
You can store the data local using a XML file. 您可以使用XML文件在本地存储数据。 You can read the XML File on startup with a DOM Reader 您可以在使用DOM Reader启动时读取XML文件
http://www.ibm.com/developerworks/library/x-android/ http://www.ibm.com/developerworks/library/x-android/
If you have lots of data you can use a SQLite Database 如果您有大量数据,则可以使用SQLite数据库
http://developer.android.com/training/basics/data-storage/databases.html http://developer.android.com/training/basics/data-storage/databases.html
If there are not too much data you can keep them in SharedPreferences 如果没有太多数据,则可以将其保留在SharedPreferences中
You access them with PreferenceManager.getDefaultSharedPreferences() 您可以使用PreferenceManager.getDefaultSharedPreferences()访问它们
Once application exit or destroy that will remove all data . 一旦应用程序退出或销毁,将删除所有数据。 if you want to access after relaunch you should save your data as per your requirement . 如果要在重新启动后访问,则应根据需要保存数据。 like local or web. 例如本地或网络。 its deepen you. 它加深了你。 right now you can store data in preference so it will useful after relaunch the application. 现在,您可以优先存储数据,这样在重新启动应用程序后将很有用。 I think this is better for you : How to use SharedPreferences in Android to store, fetch and edit values 我认为这对您更好: 如何在Android中使用SharedPreferences来存储,获取和编辑值
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.