Android导航回“活动";不要重新加载父母
我有一个场景,我单击一个ListFragment并旋转一个新的Activity,如下所示:
I have a scenario where I am clicking on a ListFragment and spinning up a new Activity like below:
public void onListItemClick(ListView l, View v, int position, long id) {
super.onListItemClick(l, v, position, id);
Intent intent = new Intent(getActivity(), VenueBeerActivity.class);
Parcelable wrapped = Parcels.wrap(mAdapter.getItem(position));
intent.putExtra("venue", wrapped);
startActivity(intent);
}
这可以正常工作并显示新活动.
This works fine and displays the new activity.
我修改了此活动清单,使其指向其父活动(在本例中为主要活动)
I've modified this activities manifest so it points back to its parent activity (in this case main activity)
但是我遇到的问题是,当按下后退按钮时,它会重新加载整个父级.父级是一个列表,我不希望它重新加载用户位置.我该如何预防?
However the problem I have is when the back button is pressed, it reloads the entire parent. The parent is a list and I don't want it to reload the users position. How can I prevent this?
请注意.父级包含页面标签条".
As a note. The parent houses a Page Tab Strip.
我确定这是一个相对简单的解决方法...
I'm sure this is a relatively simple fix...
后退按钮"是什么意思?它是工具栏中的向上按钮吗?如果是这种情况,请将VenueBeerActivity
中的onOptionsItemSelected
编辑为:
What do you mean by "back button"? Is it the up button in the toolbar? If that's the case, edit the onOptionsItemSelected
in your VenueBeerActivity
to:
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id) {
case android.R.id.home:
onBackPressed();
return true;
}
return super.onOptionsItemSelected(item);
}
因此,当用户按下向上按钮时,它将在导航栏中显示后退按钮的行为.
So when user press the Up button it will get the behavior of the back button in the navigation bar.