在我的应用程序中,我只想在第一次运行时运行启动画面一次,但问题是我已经在 Manifest
中放置了这一行:android:noHistory="true "
如果我按下后退按钮并退出应用程序,效果很好,但请注意该应用程序仍在后台运行,当我按下应用程序图标时,它会再次返回到初始屏幕,然后是我的注册页面。我希望在重新打开我的应用程序时直接重定向到注册页面。
我该怎么做?提前感谢您的任何建议。
最佳答案
这就是我实现它的方式!希望对您有所帮助!
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
public class check extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
SharedPreferences settings=getSharedPreferences("prefs",0);
boolean firstRun=settings.getBoolean("firstRun",false);
if(firstRun==false)//if running for first time
//Splash will load for first time
{
SharedPreferences.Editor editor=settings.edit();
editor.putBoolean("firstRun",true);
editor.commit();
Intent i=new Intent(check.this,Splash.class);
startActivity(i);
finish();
}
else
{
Intent a=new Intent(check.this,Main.class);
startActivity(a);
finish();
}
}
}
关于android - 如何像启动画面一样只运行一次 Activity ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18612824/