检查android活动是否是第一次启动

时间:2016-01-22 23:02:29

标签: android android-activity start-activity

我希望这项任务只是eseguite的时间。当我在此活动中返回时没有eseguite

public void onStart() {
    super.onStart();
    if (mMovies.le) {
        TaskClass nuovo = new TaskClass();
        nuovo.execute("http://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&");
        Log.v("prova", "inizio");
    }

}

1 个答案:

答案 0 :(得分:0)

你必须使用这样的SharedPreferences

final String PREFS_NAME = "MyPrefsFile";
SharedPreferences firstPref = getSharedPreferences(PREFS_NAME, 0);
if (firstPref.getBoolean("First_Time", true)) {   
  //Do first operation
  if (mMovies.le) {
      TaskClass nuovo = new TaskClass();
      nuovo.execute("http://api.themoviedb.org/3/discover/movie?sort_by=popularity.desc&");
      Log.v("prova", "inizio");
  }      
  firstPref.edit().putBoolean("First_Time", false).commit(); 
}

您的活动的onCreate()方法