从A活动到B活动,B到c,但是当回到A并点击后退按钮时,需要三次点击事件返回。我在onbackpressed方法中调用了finish()方法,看起来finish()方法工作不正常或者是其他任何原因,任何帮助都会受到赞赏
这是我的代码
public class A extends Activity {
TextView text_whatsapp;
ImageView image_whatsapp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about_whatsapp);
text_whatsapp = (TextView) findViewById(R.id.text_whatsapp);
image_whatsapp = (ImageView) findViewById(R.id.image_whatsapp);
}
@Override
public void onBackPressed() {
finish();
super.onBackPressed();
}
}
public class B extends Activity {
TextView text_whatsapp;
ImageView image_whatsapp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.availability);
}
@Override
public void onBackPressed() {
startActivity(new Intent(B.this, A.class));
super.onBackPressed();
}
}
public class C extends Activity {
TextView text_whatsapp;
ImageView image_whatsapp;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.c);
}
@Override
public void onBackPressed() {
startActivity(new Intent(C.this, B.class));
super.onBackPressed();
}
}
答案 0 :(得分:1)
在活动C中使用如下。
@Override
public void onBackPressed() {
super.onBackPressed();
startActivity(new Intent(C.this, B.class));
finish();
}
在活动B中使用如下。
@Override
public void onBackPressed() {
super.onBackPressed();
startActivity(new Intent(B.this, A.class));
finish();
}
在活动A中使用如下。
@Override
public void onBackPressed() {
super.onBackPressed();
finish();
}
答案 1 :(得分:0)
当你从A到B再到B到C时调用完成然后它不会让你按3退出应用程序