【发布时间】:2015-01-27 18:12:20
【问题描述】:
我有 3 个屏幕,屏幕 1、屏幕 2、屏幕 3。
这是我正在实施的那种后退导航,
屏幕 3 -> 屏幕 2 -> 屏幕 1。
这是我下面的 屏幕 1
代码public class Screen1 extends Activity implements OnClickListener{
Button button1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button1 = (Button)findViewById(R.id.button1);
button1.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId())
{
// This is where the intent starts to display the second Screen
case R.id.button1:
Intent started = new Intent(Screen1.this,Screen2.class);
startActivity(started);
break;
}
}
}
屏幕 2
public class Screen2 extends Activity implements OnTouchListener{
ListView displaylist;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.screen2);
// Please ignore this part of the code it just displays the list of items
displaylist = (ListView)findViewById(R.id.listView1);
String[] listofitems = {"A","B","C","W"};
ArrayAdapter<String> lists = new ArrayAdapter<String>(Screen2.this, android.R.layout.simple_list_item_1, listofitems);
displaylist.setAdapter(lists);
displaylist.setOnTouchListener(this);
}
// This is where the intent starts to display the Third Screen
@Override
public boolean onTouch(View v, MotionEvent event) {
// TODO Auto-generated method stub
Intent started2= new Intent(Screen2.this,Screen3.class);
startActivity(started2);
return true;
}
}
屏幕 3
public class Screen3 extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Displays some layout
}
}
我目前的问题
我目前的问题是后退导航(当我按下后退按钮时)按以下顺序进行
屏幕3 -> 屏幕3 -> 屏幕2 -> 屏幕1
我的问题
为什么当我按下返回按钮时 Screen3 又显示出来了?这是某种错误吗?
来自类似的question David Wasser comment 说
If your navigation is standard, then 1 starts 2 and the BACK button goes back to 1. 2 starts 3 and the BACK button goes back to 2. You don't need to do anything special to get this
测试设备
安卓模拟器
API 级别:19
注意:我不想用 Actionbar 做这个
【问题讨论】:
标签: android android-intent navigation back