2017-10-20 173 views
1

我需要回調,如果應用程序從後臺恢復,但onResume()始終被稱爲活動啓動。onResume()僅當恢復活動

我打開一個活動:

Intent i = new Intent(this, Spedizione.class); 
i.putExtra("codice", result.getText()); 
startActivity(i); 

的onResume代碼:

@Override 
    protected void onResume() { 
    super.onResume(); 
    AlertDialog.Builder builder = new AlertDialog.Builder(this); 
      builder.setMessage("Are you sure?").setPositiveButton("Yes", dialogClickListener) 
        .setNegativeButton("No", dialogClickListener).show(); 
    } 

當開放活動onResume()隨時撥打AlertDialog,不僅當應用程序是從背景簡歷,爲什麼呢?

我只需要回調,只有當應用程序從後臺重新打開。

回答

3

OnResume()是一個每次都會被調用的活動生命週期方法。你可以通過onRestart()來調用你的條件,或者維護一個布爾值來檢查firstTimeCall或不。

+0

該文檔解釋它:https://developer.android.com/guide/components/activities/activity-lifecycle.html#alc –