0

我打了电话

Intent intent = new Intent(activity, Main_AllLatestNews.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);

但是,当我在课堂上单击后退按钮时Main_AllLatestNews,它应该退出应用程序而不是返回到以前的活动。

4

3 回答 3

1
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);
    }
于 2012-06-25T08:38:47.070 回答
1

试试这个:

Intent intent = new Intent(activity, Main_AllLatestNews.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
activity.startActivity(intent);
activity.finish();
于 2012-06-25T08:39:33.240 回答
0

在活动 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);
}
于 2012-06-26T04:50:38.097 回答