简体   繁体   中英

Splash Screen that will check if user is already registered

I would like my splash screen to check if the user is already registered: if the person is already registered, it will go aa login screen. Else, it will go a registration activity. I have already created a database class in the same package. The problem I am facing is that this splash screen is not doing its job. When I run the project, it takes me directly to the login screen. I have a feeling the splash screen is skipped... Please Help!

public class SplashScreen extends Activity
{

protected void onActivityResult(int reqCode, int resultCode, Intent data)
 {

super.onActivityResult(reqCode, resultCode, data); 
if (resultCode != -1)
{
    finish();
    Database db = new Database(this);
    int k = db.getCount();
    Log.d("The Number of Row : ", String.valueOf(k));


    if (k != 0)//If we already have an entry in the database then will move from the splash screen to the loginCode activity
    {
      finish();
      Intent intent1 = new Intent(SplashScreen.this, LoginCode.class);
      startActivity(intent1);
      overridePendingTransition(R.anim.action_fade_in, R.anim.action_fade_out);
    }

    else//if launching app the first time then we will need to register
    {
      finish();
      Intent intent2 = new Intent(SplashScreen.this, RegPasscode.class);
      startActivity(intent2);
      overridePendingTransition(R.anim.action_fade_in, R.anim.action_fade_out);
    }
    db.close();

  }
else
{
    Log.i("RobMeNot", "Administration enable FAILED!");

}

}

In your AndroidManifest.xml set this filter :

 <intent-filter>

            <action android:name="android.intent.action.MAIN"/>

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

to your SplashScreen activity and remove it from LoginScreen .

In the end your activity should look like this :

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

And why are you doing all that logic in onActivityResult ? You should check what screen to launch in onCreate like this :

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    try
    {
        Database db = new Database(this);
        int k = db.getCount();
        Log.d("The Number of Row : ", String.valueOf(k));

        if (k != 0)//If we already have an entry in the database then will move from the splash screen to the loginCode activity
        {
            finish();
            Intent intent1 = new Intent(SplashScreen.this, LoginCode.class);
            startActivity(intent1);
            overridePendingTransition(R.anim.action_fade_in, R.anim.action_fade_out);
        }

        else//if launching app the first time then we will need to register
        {
            finish();
            Intent intent2 = new Intent(SplashScreen.this, RegPasscode.class);
            startActivity(intent2);
            overridePendingTransition(R.anim.action_fade_in, R.anim.action_fade_out);
        }
    }finally {
        db.close();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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