Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Activity Flow (Login or Register and go to Home)

I am building an application which requires user authentication. First time a user opens the app should login or register to continue to the home screen of the app which loads some posts..

i should mention that the home screen should be a FragmentActivity to allow user navigate between 2-3 tabs.. this means that i should have another Activity (for the login screen or register) to allow the user to continue later to home.

MainActivity
    |
    |
    --> Check If user logged in
              |       |
              |       |
              |       --> Start Login Activity (Or Register From Here)
              |
              --> Start Home Activity (FragmentActivity with 2-3 tabs-fragments)

Right now in the main Activity i am checking through shared preferences if user already logged in and then i start the FragmentActivity or the login Activity if user has not logged in.

I don't know if this is a problem, but when one of these two activities has started if i press back it goes on a blank screen and nothing happens. Seems logic because this is the MainActivity and its actually blank. i only have an if statement there to proceed to the appropriate activity.

Is this a nice approach or should i develop this with another way?


1 Answers

You can finish your main activity just after you navigate to home/login screen ex:

Intent intent=new Intent(this,Home.class);
startActivity(intent);
finish();

By doing this if user presses a back button on login or home page blank page wont be visible.

Also you can use your main activity as splash screen where you show some image and in background decide to go to login/home activity.

like image 130
vipul mittal Avatar answered Nov 03 '25 12:11

vipul mittal



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!