调用完成()移除活动栈的活动? [英] Calling finish() removes the activity from activity stack?

查看:143
本文介绍了调用完成()移除活动栈的活动?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做了一个应用程序,我

  1. 在启动活动PIN我开始后活动A (活动A有 noHistory = TRUE ,因此它会没有留在堆栈)。
  2. 如果没有脚已经成立; PinActivity 也开始活动 NewPinActivity
  3. 在设定针后, NewPinActivity 要求完成()并返回到 PinActivity 。在那里你会给予适当的脚,它会调用完成()它,它会再次移至活动A (由于活动A noHistory = TRUE ,所以我要开始的新实例活动A )。 我的问题是,如果我preSS 返回活动A ,有时候我的 NewPinActivity 显示了一次就算我叫完成()就可以了。
解决方案

没有,你应该在第二个活动是:

 意图exitIntent =新的意图(这一点,MainActivity.class);
        exitIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(exitIntent);
        MainActivity.exitHandler.sendEmptyMessage(0);
 

和在MainActivity:

  exitHandler =新的处理程序(){
    公共无效的handleMessage(信息MSG){
        super.handleMessage(MSG);
        开关(msg.what){
        情况下0:
            //清除任何你喜欢这里的信息
            MainActivity.this.finish();
            打破;
        }
    }
};
 

I have made an application where I

  1. start activity 'Pin' after I start activity A(activity A has noHistory= true, so it will not stay on stack).
  2. If no pin has been set up; PinActivity also starts an activity NewPinActivity.
  3. After setting pin, NewPinActivity calls finish() and goes back to PinActivity. Where you will give appropriate pin, it will call finish() on it and it will move again to activity A(Since activity A had noHistory=true, so I have to start a new instance of activity A). My problem is, if I press back from activity A, sometimes my NewPinActivity shows up again even if I called finish() on it.

解决方案

No, you should use in a second activity:

        Intent exitIntent = new Intent(this,MainActivity.class);
        exitIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP|Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(exitIntent);
        MainActivity.exitHandler.sendEmptyMessage(0);

and in MainActivity:

    exitHandler = new Handler() {
    public void handleMessage(Message msg) {
        super.handleMessage(msg);
        switch (msg.what) {
        case 0:
            // clear any informations you like here
            MainActivity.this.finish();
            break;
        }
    }
};

这篇关于调用完成()移除活动栈的活动?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆