Define different Android home screens

This question I already asked for swift

I am making an app in Android, in which I check if a user is already registered or not.

If you are registered, I show you one screen, but if you are not registered I show you another.

How can I do to display one screen or another?

Here my code:

if (comprobarUsuario(String datos)) {
   //Existe el usuario, por lo que se va directamente a la app
}
else {
   //No existe el usuario, por lo que se muestra el formulario
}
 3
Author: Comunidad, 2016-09-02

2 answers

If they are Activity your screens simply perform the intent to open them:

    Intent intent;
    if (comprobarUsuario(String datos)) {
        //Existe el usuario, por lo que se va directamente a la app
        intent = new Intent(this, MainActivity.class);
    }else {
        //No existe el usuario, por lo que se muestra el formulario
        intent = new Intent(this, LoginActivity.class);
    }
    //Inicia la Activity.
    startActivity(intent);

If the "screens" were Fragments it would be done by a transaction replacing the fragment:

    FragmentManager fragmentManager;
    FragmentTransaction fragmentTransaction;
    if (comprobarUsuario(String datos)) {
        //Existe el usuario, por lo que se va directamente a la app
        Fragment fragment = new FragmentMain();
        fragmentManager = getSupportFragmentManager();
        fragmentTransaction =
                fragmentManager.beginTransaction();
        fragmentTransaction.replace(android.R.id.content, fragment);
        fragmentTransaction.commit();
    }   else {
        //No existe el usuario, por lo que se muestra el formulario
        Fragment fragment = new FragmentLogin();
        fragmentManager = getSupportFragmentManager();
        fragmentTransaction =
                fragmentManager.beginTransaction();
        fragmentTransaction.replace(android.R.id.content, fragment);
        fragmentTransaction.commit();
    }
 1
Author: Jorgesys, 2016-09-02 16:16:48

Create two Activitys and launch them according to what you need:

Intent intent = null;

if (comprobarUsuario(String datos)) {
    intent = new Intent(this, AplicacionActivity.class);
} else {
    intent = new Intent(this, RegistrarUsuarioActivity.class);
}
startActivity(intent);
 2
Author: joc, 2016-09-02 13:16:08