androidAPP长期在后台的话,会被系统回收资源,一些局部变量会被清除
Activity中需要以下操作保存有用的数据
1.
-
@Override
-
protected void onCreate(Bundle savedInstanceState) {
-
super.onCreate(savedInstanceState);
-
if (savedInstanceState != null) {
-
String username = savedInstanceState.getString("username");
-
String password = savedInstanceState.getString("password");
-
ClientSDKSingleton.getInstance().setUsername(username);
-
ClientSDKSingleton.getInstance().setPassword(password);
-
Log.i(TAG, "onCreate username=" + username + " password="
-
+ password);
-
}
-
}
-
-
@Override
-
protected void onSaveInstanceState(Bundle outState) {
-
super.onSaveInstanceState(outState);
-
String username = ClientSDKSingleton.getInstance().getUsername();
-
String password = ClientSDKSingleton.getInstance().getPassword();
-
outState.putString("username", username);
-
outState.putString("password", password);
-
}
2
-
static {
-
System.loadLibrary("faac");
-
System.loadLibrary("faad");
-
System.loadLibrary("ffmpeg");
-
System.loadLibrary("OSbase");
-
System.loadLibrary("weibosdkcore");
-
}
以上两端代码可以写在BaseActivity中,让所有Activity都继承BaseActivity
阅读(4032) | 评论(0) | 转发(0) |