好的,我在onCreate和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执行。据我所知,我没有恢复。
请赐教我
答案 0 :(得分:1)
你得到重复,因为代码运行了两次。从头开始的活动继续onCreate,onStart,onResume,用户在屏幕上看到活动。暂停应用程序后,您将调用onPause和onStop(如果活动不可见),并且在恢复时您将调用onStart和onResume。
这个Google document的整个活动生命周期有一个很好的图表和很好的解释,这是关于这个主题的精彩读物。