简体   繁体   English

使用noHistory完成旧活动

[英]Finishing old activity with noHistory

I'm trying to understand finishing an activity and starting another. 我试图了解完成一项活动并开始另一项活动。

<activity
            android:name="com.blabla.game.OyunActivity"
            android:label="@string/title_activity_oyun"
            android:noHistory="true" >
        </activity>

OyunActivity : Oyun活动:

int number = 1;
while(true)
{
if(number == 52)
{
            Intent intent = new Intent(this, GameOver.class);
            startActivity(intent);
            finish();
}
number++;
Log.d("TAG", number);
}

It's starting GameOver activity but OyunActivity not finishing. 它正在启动GameOver活动,但OyunActivity尚未结​​束。 It's keeping increase number variable and outputting it to Logcat. 它保持增加数变量并将其输出到Logcat。

PS : Actually my code not really stupid like this. PS:实际上我的代码不是真的像这样愚蠢。 I'm trying to make a basic game. 我正在尝试制作基本游戏。 It should stop and open GameOver activity when number = 52 当数字= 52时,它应该停止并打开GameOver活动

Should be break instead of finish() 应该break而不是finish()

 int number = 1;
while(true)
{
if(number == 52)
{
            Intent intent = new Intent(this, GameOver.class);
            startActivity(intent);
            return;
}
number++;
Log.d("TAG", number);
}

This question will be helpful for you, I think. 我认为, 这个问题对您会有所帮助。

Quotation : 报价单:

You can use finish() method or you can use:

android:noHistory="true"

And then there is no need to call finish() anymore.

<activity android:name=".ClassName" android:noHistory="true" ... />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM