Android:清除活动堆栈

时间:2013-09-04 07:38:31

标签: android android-activity

我想在点击Logout Button后清除所有活动。为此我使用了以下代码。请告诉我实施它的正确方法。

public class LogoutListner implements OnClickListener {

    private Activity mActivity;

    public LogoutListner(Activity a) {
        this.mActivity = a;
    }

    @Override
    public void onClick(View arg0) {
        Intent intent = new Intent(mActivity, LoginActivity.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_HISTORY);
        mActivity.startActivity(intent);
    }

1 个答案:

答案 0 :(得分:3)

Intent intent = new Intent(mActivity, LoginActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
mActivity.startActivity(intent);