2016-03-07 79 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和解决问题。 –