假設應用程序檢查,如果一開始是她的第一次運行,用下面的代碼:當應用程序更新時,下一次啓動被視爲第一次運行?
public class MyActivity extends Activity {
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Doing things
prefs = getSharedPreferences("com.example.myAppName", MODE_PRIVATE);
}
@Override
protected void onResume() {
super.onResume();
if (prefs.getBoolean("firstrun", true)) {
// Do first run stuff here then set 'firstrun' as false
// using the following line to edit/commit prefs
prefs.edit().putBoolean("firstrun", false).commit();
}
}}
假設現在這個應用程序是通過谷歌更新播放,當應用程序再次運行時,該代碼就會認爲這是他的首先開始? Sahred首選項在更新過程中被刪除?
謝謝您的時間,
Flagg。
否。共享首選項將保留。 –