代码在 onCreate!什么时候setContentView(R.layout.manual);
在外面if
它工作。但是我搬进setContentView(R.layout.manual);
去if
不能工作!
如下图:
if (settings.getBoolean("my_first_time", true)) {
setContentView(R.layout.manual); // can not work
}
但Log.d("Comments1", "First time");
总是有效
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
final String PREFS_NAME = "MyPrefsFile";
SharedPreferences settings = getSharedPreferences(PREFS_NAME, 0);
if (settings.getBoolean("my_first_time", true)) {
//the app is being launched for first time, do something
Log.d("Comments1", "First time");//this can be showed on logCat!
setContentView(R.layout.manual);// this can not work
// record the fact that the app has been started at least once
settings.edit().putBoolean("my_first_time", false).commit();
}
}