public class MYApplication extends Application {
String property;
setter getter
}
上面的代码确保属性不会被android操作系统收集,如果长时间不使用的话。Android应用程序数据不应该由android操作系统发布
public class MYApplication extends Application {
String property;
setter getter
}
上面的代码确保属性不会被android操作系统收集,如果长时间不使用的话。Android应用程序数据不应该由android操作系统发布
编号Android有权在任何时候终止任何应用程序,如果它觉得需要。如果设备内存不足,则为Even foreground processes can be killed。这意味着Application
对象将被销毁并且其所有属性都会丢失。
确保您的应用程序的临时状态不会丢失的唯一方法是适当地响应Android提供的生命周期事件,或者持续存储值。
如果您想为您的应用程序存储String
why not use Preferences?这意味着即使设备关闭,该值也不会丢失。
private static final String PREFERENCE_MYSTRING = "mystring";
static String getProperty(Context context) {
return PreferenceManager.getDefaultSharedPreferences(context)
.getString(PREFERENCE_MYSTRING, "");
}
static void setProperty(Context context,String value) {
PreferenceManager.getDefaultSharedPreferences(context)
.edit()
.putString(PREFERENCE_MYSTRING, value)
.commit();
}
(我不太知道什么getter
和setter
是你的代码示例中,但我不认为这是相关的。)
据我了解,它的中心,如果你重写onDestroy()
想要阻止Android操作系统杀死您的进程。