我一直在研究Android SDK平台,有点不清楚如何保存应用程序的状态.因此,考虑到'Hello,Android'示例的这种小型重新设计:
package com.android.hello;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class HelloAndroid extends Activity {
private TextView mTextView = null;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTextView = new TextView(this);
if (savedInstanceState == null) {
mTextView.setText("Welcome to HelloAndroid!");
} else {
mTextView.setText("Welcome back.");
}
setContentView(mTextView);
}
}
Run Code Online (Sandbox Code Playgroud)
我认为这对于最简单的情况就足够了,但无论我如何远离应用程序,它总是以第一条消息响应.
我确信解决方案就像覆盖onPause或类似的那样简单,但我已经在文档中捅了大约30分钟左右,并且没有找到任何明显的东西.
我有SearchCritiera对象,我把它变成单例并将此变量声明为静态,现在的问题是,如果我离开我的应用程序保持打开几个小时,Android操作系统删除静态对象,我怎样才能确保静态对象不应该是被OS删除.
就像我知道有很少的关键词
Weekreference和softreference是否有任何strongreference关键字可以告诉Android OS不删除引用?
我已经在域对象中编写了我的应用程序逻辑(以启用多个用户界面并移植到其他平台),现在我正在为用户界面实现活动.
考虑到每个活动都需要序列化其状态,确保我的域对象只被序列化一次的最佳方法是什么?