1

I have a login screen in my Android App and after login the main screen comes.

What is the most appropriate way to not allow the login screen to appear again after successful login.

Should we put a check in the onCreate of the login Activity. Set up appropriate Flag to the Intent of main screen

  • if this is not appropriate what would be the most appropriate flag for this.

Another problem is that from the main screen we have links to various sections of the App. The user may leave the app at any page of any subsection of the app. For eg: the user may view various products by using the product section from the Main Screen.

  • Is it possible to always start off from this main screen even when there is some error in some subsection activity. For eg: if any product page crashes , the app returns to Starting Page of Products whereas we require it to start from the Main Screen.

  • Is it possible through some flag setting in the activity tag or do we need to check some property in onCreate and accordingly navigate back to Main-Screen.

Kindly update.

Thanks

Praneeth
  • 1,260
  • 18
  • 37
user2779311
  • 1,688
  • 4
  • 23
  • 31

3 Answers3

0

You can use Intent Flag for such result.in my app i use below code -

Intent i = new Intent(mContext, DashBoardActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(i);
finish();

It this way login screen not appear after login if user presses back button. Also set a flag in SharedPreference say is_user_login = true and in next launch of app check preference value and take action according to it. Hope it will help you.

Ravi Bhandari
  • 4,682
  • 8
  • 40
  • 68
0

What is the most appropriate way to not allow the login screen to appear again after successful login.

You can use a flag or use a sharedPreference for this to maintain the state of the login.

Is it possible to always start off from this main screen even when there is some error in some subsection activity. For eg: if any product page crashes , the app returns to Starting Page of Products whereas we require it to start from the Main Screen.

Do proper exception handling and in the catch block redirect to main screen and call finish()

prince
  • 1,129
  • 1
  • 15
  • 38
0

prevent login screen using this link

Add into your MainScreen remove this line super.onBackPressed();

  @Override
    public void onBackPressed() {
        moveTaskToBack(true);

    } 

if any problem just ping me

Community
  • 1
  • 1
Arpit Patel
  • 7,212
  • 5
  • 56
  • 67