【问题标题】:Check if android activity is the first start [duplicate]检查android活动是否是第一次启动[重复]
【发布时间】:2016-01-22 23:02:29
【问题描述】:

我希望这项任务是 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");
    }

}

【问题讨论】:

    标签: android android-activity start-activity


    【解决方案1】:

    你必须像这样使用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(); 
    }
    

    在您的 Activity 的 onCreate() 方法中

    【讨论】:

      猜你喜欢
      • 2011-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-12-19
      • 2015-01-13
      • 2019-03-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多