Amit
Amit

Reputation: 3990

android: choose which activity should be first activity

I have a login screen, that i have successfully deleted from history once the user logs in.

But even now if i press the back buttom, and open the application again, it shows the login screen. How do i ensure that once the user logs in, then the application should only show the home screen?

here is the code that i am using to disable history

android:noHistory="true"

i guess i should add an override in the onCreate of my application class?

   @Override
    public void onCreate(){
        super.onCreate();
        // anything else that we need to do, when app is run.
    }

Upvotes: 2

Views: 1529

Answers (2)

Sol
Sol

Reputation: 320

You can add method to login activity

private void successfulLogin() {
  startActivity(new Intent(this, MainActivity.class));
  finish();
}

Login activity will be destroyed.

Upvotes: 1

kaspermoerch
kaspermoerch

Reputation: 16570

The easy solution is to add a new activity before the Login/HomeScreen activities. In this activity you check if Login is needed and fire the desired Activity:

public class StartupActivity extends Activity {
   public void onCreate() {
     if( loginRequired ) {
       //Start the login activity
     }
     else {
       //Start the home screen activity
     }

     finish();
   }
}

Upvotes: 1

Related Questions