我打了电话
Intent intent = new Intent(activity, Main_AllLatestNews.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);
但是,当我在课堂上单击后退按钮时Main_AllLatestNews
,它应该退出应用程序而不是返回到以前的活动。
我打了电话
Intent intent = new Intent(activity, Main_AllLatestNews.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);
但是,当我在课堂上单击后退按钮时Main_AllLatestNews
,它应该退出应用程序而不是返回到以前的活动。
Backpressed destroy the current activity
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
this.finish();
Intent intent = new Intent(activity, Main_AllLatestNews.class);
startActivity(intent);
return true;
}
return super.onKeyDown(keyCode, event);
}
试试这个:
Intent intent = new Intent(activity, Main_AllLatestNews.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);
activity.finish();
在活动 D 中使用代码如下所示
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
// do something on back.
this.finish();
Intent i = new Intent(Dactivity.this, AActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
return true;
}
return super.onKeyDown(keyCode, event);
}