【问题标题】:finish() sometimes not working完成()有时不工作
【发布时间】:2014-12-03 23:13:23
【问题描述】:

我有不同的级别类,我从一个函数中调用它们。 问题是有时 Endscreen.Class 没有关闭...但它只发生在 Level5 及以上。

我在 Endscreen.class 中的函数:

public void NextLevel(View v){
    switch(currentLevel){
        case 1:
            Intent nLvl1 = new Intent (this, Level2.class);
            startActivity(nLvl1);
            finish ();
            break;
        case 2:
            Intent nLvl2 = new Intent (this, Level3.class);
            startActivity(nLvl2);
            finish ();
            break;
        case 3:
            Intent nLvl3 = new Intent (this, Level4.class);
            startActivity(nLvl3);
            finish ();
            break;
        case 4:
            Intent nLvl4 = new Intent (this, Level5.class);
            startActivity(nLvl4);
            finish ();
            break;
        case 5:
            Intent nLvl5 = new Intent (this, Level6.class);
            startActivity(nLvl5);
            finish ();
            break;
        case 6:
            Intent nLvl6 = new Intent (this, Level7.class);
            startActivity(nLvl6);
            finish ();
            break;
        case 7:
            Intent nLvl7 = new Intent (this, Level8.class);
            startActivity(nLvl7);
            finish ();
            break;
        case 8:
            Intent nLvl8 = new Intent (this, Level9.class);
            startActivity(nLvl8);
            finish ();
            break;
        case 9:
            Intent nLvl9 = new Intent (this, LevelSelect.class);
            startActivity(nLvl9);
            finish ();
            break;
    }
}

【问题讨论】:

    标签: android activity-finish


    【解决方案1】:

    很容易解决这个问题。对于每个意图,添加以下内容:

    intentName.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    

    这将以您希望的方式摆脱当前活动到finish()

    您可以阅读此here 上的文档。

    【讨论】:

      【解决方案2】:

      我解决了这个问题:

      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK|Intent.FLAG_ACTIVITY_NEW_TASK);
      

      【讨论】:

        猜你喜欢
        • 2011-11-01
        • 2018-12-17
        • 2019-11-22
        • 1970-01-01
        • 2012-01-25
        • 2017-05-02
        • 2013-10-28
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多