Android Login – Best implementation

I’m planning to implement an Android application that requires a login screen.

If the user opens the activity something like this should happen:

  • Failed resolution of: Lcom/google/devtools/build/android/desugar/runtime/ThrowableExtension;
  • Could not find method android() for arguments
  • Fetching big amount of data, what is the best way to go?
  • Android 4.0 ICS turning HttpURLConnection GET requests into POST requests
  • (Android Xamarin) Get Resource string value instead of int
  • failed to resolve:
    1. If user is logged in, goto 3
    2. If user is not logged in open the login screen and perfom login
    3. Show my application content

    So, what’s the “correct” way of implementing a login?

    1. Implement a StartActivity that perfoms the check if the user is logged in, implement a LoginActivity that implements the logging and an ApplicationActivity that actually implements the application logics?
    2. Implement just one Activity and handle the login by using multiple views which I show according to the application state?

    Are there any examples or tutorials for this scenario?

    Related posts:

    How to implement expandable panels in Android?
    How does storage access change on Android 6?
    Convert UTC into Local Time on Android
    “Canvas: trying to draw too large bitmap” when Android N Display Size set larger...
    Lockscreen is displayed between activities
    Higher API calls when lower SDK targeted
  • Changing coding style due to Android GC performance, how far is too far?
  • Suggestions for entering mobile development — pure iPhone SDK, Android SDK, Mono Touch or Titanium?
  • How do I fix “Failed to sync vcpu reg” error?
  • How to hide Android tabs using Xamarin Forms custom renderer?
  • Android text style missing light, medium, thin,
  • Android Paint: how to get “airbrush” effect?
  • 4 Solutions collect form web for “Android Login – Best implementation”

    I don’t think that there is a “correct” way of doing this. Both solutions you describe seem fine to me, although I would merge StartActivity and LoginActivity into a single one.

    You can even just have a MainActivity that shows a Login Dialog. You could store the user’s login/password with SharedPreferences, and on app start check the preferences and auto-login the user or else show the login dialog. If you do this you should also add a logout functionality.

    I had developed a microblogging application recently which had a login activity and which on logging in redirects user to his home page.

    The way, I did it was to keep the login activity and Application Activity separate and if the user supplied credentials were right, the application activity was started by

    startActivity(new Intent(LoginActivity.this, ApplicationActivity.class)

    Later on I added a Checked Box and on ticking it, the user name and password were written to SharedPreferences and so the next time onwards user was straightaway directed to his home page.

    1. Login Activity : Taken you to the login screen if user is not logged in. Check SharedPreference for logged in user. If user is logged in, it will open up Application Activity.
    2. ApplicationActivity : The landing page of your application.
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.