我正在努力了解完成一项活动并开始另一项活动。
<activity
android:name="com.blabla.game.OyunActivity"
android:label="@string/title_activity_oyun"
android:noHistory="true" >
</activity>
OyunActivity:
int number = 1;
while(true)
{
if(number == 52)
{
Intent intent = new Intent(this, GameOver.class);
startActivity(intent);
finish();
}
number++;
Log.d("TAG", number);
}
它正在开始GameOver活动,但OyunActivity没有完成。它保持增加数量变量并将其输出到Logcat。
PS:实际上我的代码并不像这样愚蠢。我正在尝试制作基本游戏。当number = 52 时,它应该停止并打开GameOver活动答案 0 :(得分:0)
应该是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);
}
答案 1 :(得分:-1)
This question会对你有所帮助。
报价:
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" ... />