Android 仅在第一次运行Splash布局

Android 仅在第一次运行Splash布局,android,sharedpreferences,splash-screen,launcher,Android,Sharedpreferences,Splash Screen,Launcher,我只想在应用程序第一次启动时启动启动屏幕。我的启动屏幕与另一个屏幕相连,这也是第一次出现。 我的启动屏幕代码是: public class SplashPage extends Activity{ private static int startPage = 7000; SharedPreferences prefs = null; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(

我只想在应用程序第一次启动时启动启动屏幕。我的启动屏幕与另一个屏幕相连,这也是第一次出现。 我的启动屏幕代码是:

public class SplashPage extends Activity{
private static int startPage = 7000;
SharedPreferences prefs = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splashpage);

    prefs = getSharedPreferences("com.tech.spam", MODE_PRIVATE);

        }
@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();
     if (prefs.getBoolean("firstrun", true)) {
            calll();
        }
     if (prefs.getBoolean("firstrun", false)) {
         finish();
         startActivity(new Intent(SplashPage.this,MainActivity.class));
        }
            //prefs.edit().putBoolean("firstrun", false).commit();
            //finish();

}
private void calll() {
    // TODO Auto-generated method stub
    Animation anim = AnimationUtils.loadAnimation(this, R.anim.move);
    ImageView iv = (ImageView) findViewById(R.id.imageView1);
    iv.startAnimation(anim);



    Animation anim1 = AnimationUtils.loadAnimation(this, R.anim.move);
    TextView ivvv = (TextView) findViewById(R.id.textView1);
    ivvv.startAnimation(anim1); 



       new Handler().postDelayed(new Runnable() {          
            public void run() {    
                Intent intent = new Intent(SplashPage.this, SplashPageTutorial.class);

                startActivity(intent);

                overridePendingTransition(R.anim.fade, R.anim.hold);
                finish();
                }
            },     
        startPage);

}
现在我想做的是,第一次启动应用程序时,Splash运行7秒钟,然后打开下一个屏幕,7秒钟后与Splash链接,然后在第二个屏幕之后,我的主要活动开始。 现在我想做的是,当我第一次打开应用程序时,只有主要活动是启动(启动屏幕和与启动链接的屏幕现在消失了)

我使用这段代码是为了当应用程序再次打开时,布尔值返回false,并启动主活动,但不会发生

if (prefs.getBoolean("firstrun", true)) {
            calll();
        }
     if (prefs.getBoolean("firstrun", false)) {
         finish();
         startActivity(new Intent(SplashPage.this,MainActivity.class));
        }
            //prefs.edit().putBoolean("firstrun", false).commit();
            //finish();
请帮忙,我该怎么办

我的清单是:

<application android:icon="@drawable/appicon"
    android:label="@string/app_name"
    android:theme="@style/AppBaseTheme">

    <activity android:name="com.tech.spam.SplashPage"

        android:label="@string/app_name">

        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>

    </activity>
    <activity
        android:name="com.tech.spam.MainActivity"

         >

    </activity>    
    <activity
        android:name="com.tech.spam.SplashPageTutorial"
        android:theme="@style/FullscreenTheme"
        >
    </activity>

一个简单的方法是拥有一个共享的首选项变量。启动启动屏幕时,将此变量设置为true。在启动活动之前,请检查此变量是否为false,并且仅在该变量为false时启动

@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);  // Launch next activity
        finish();
    }
}

}

一个简单的方法是拥有一个共享的偏好变量。启动启动屏幕时,将此变量设置为true。在启动活动之前,请检查此变量是否为false,并且仅在该变量为false时启动

@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);  // Launch next activity
        finish();
    }
}

}

@ArslanAli没问题,thnx表示接受,请您也对答案进行投票:)只需对答案进行投票,:D,现在它有0个投票,按绿色勾号上方0上方的符号,我的答案将有一票。有助于提高声誉:D@ArslanAli没问题,谢谢接受,请你也投票给我答案:)只要投票给我答案,:D,现在它有0票,按绿色勾号上方0的符号,我的答案将有一票。有助于提高声誉:D