2016-03-07 73 views
-3

好了,所以我在的onCreate和的onResume開始活動執行onResume?

@Override 
    public void onResume() 
    { // After a pause OR at startup 
     super.onResume(); 
     Intent intent = getIntent(); 
     String name2 = intent.getStringExtra(MyAdapter.KEY_VNAME); 
     if (name2 == null){ 
      name2 = intent.getStringExtra(MainVoterView.KEY_VNAME2); 
     } 
     String Simage = intent.getStringExtra(MyAdapter.KEY_SUGGEST_IMAGE); 
     if (Simage == null){ 
      Simage = intent.getStringExtra(MainVoterView.KEY_SUGGEST_IMAGE2); 
     } 

     layoutManager = new LinearLayoutManager(Suggestion.this); 
     recyclerView.setLayoutManager(layoutManager); 
     recyclerView.setHasFixedSize(true); 
     suggestList = new ArrayList<>(); 
     requestQueue = Volley.newRequestQueue(Suggestion.this); 
     getData(); 
     adapter = new SuggestListAdapter(suggestList, Suggestion.this, name2, Simage); 
     recyclerView.setAdapter(adapter); 
    } 

這段代碼當我開始我的建議飼料加倍活動..當我暫停應用程序,然後恢復它。建議Feed已修復。我想問的是onResume在開始活動時激活。

如果是的我應該使用什麼方法?

如果每次調用Activity執行onResume時,他們爲什麼會將其稱爲onResume。對於我所知道的,這並沒有恢復。

請大家賜教

+5

【活動生命週期(http://www.tutorialspoint.com/android/android_acitivities.htm) – anaxin

回答

1

因爲代碼跑兩次你得到重複。從頭開始的活動在onCreate,onStart,onResume上,用戶在屏幕上看到活動。一旦應用程序暫停,您可以調用onPause和onStop(如果該活動不可見),並在簡歷中調用onStart和onResume。

在這個Google document的整個活動生命週期中有一個很好的圖表和很好的解釋,這是對這個主題的一個很好的閱讀。

enter image description here

+0

感謝的是,我搬到我的代碼爲唯一的onResume和解決問題。 –