Java 仅通过第一次启动运行活动
我只想在第一次跑步时开始一项活动。因此,在我运行它一次之后,它将不会再次打开Java 仅通过第一次启动运行活动,java,android,Java,Android,我只想在第一次跑步时开始一项活动。因此,在我运行它一次之后,它将不会再次打开 <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> 我有一个按钮,它把第一个开始设置为1
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
我有一个按钮,它把第一个开始设置为1
public void create (View view)
{
SharedPreferences data = getSharedPreferences("datas",Context.MODE_PRIVATE);
SharedPreferences.Editor editor = data.edit();
first_start = 1;
editor.putInt("fstart", first_start);
...
}
但当我启动此应用程序时,它再次显示此活动。。。发生了什么问题?之所以发生这种情况,是因为这是启动程序活动,而您在启动其他活动之前正在完成该活动。应该是
if (first_start == 1)
{
Intent start = new Intent(this, Main.class);
startActivity(start);
finish();
}
了解活动生命周期:将值放入
SharedReferences
后是否提交?commit();就这样!谢谢:)
if (first_start == 1)
{
Intent start = new Intent(this, Main.class);
startActivity(start);
finish();
}