How to always launch MainLauncher Activity?

TedRogersTedRogers USMember ✭✭✭✭

I have an application that has two activities. One is a LoginActivity which is tagged as the "MainLauncher" and the other is the MainActivity of the app. I need to go through the LoginActivity prior to going to the MainActivity to gather some user information.

When the app crashes and gets restarted it goes directly back to my MainActivity thus putting me in a bad state where I don't have the user information that I need. This seems to happen in other cases too (on some phones) but haven't nailed them all down.

I have my MainActivity tagged as SingleTask so that if I get activated via a notification or from the home screen it will not create a new MainActivity if the app is already running.

How do I make sure that when the application starts up, it always goes to my "MainLauncher" LoginActivity?

Ted

Posts

  • TedRogersTedRogers USMember ✭✭✭✭
    edited April 2014

    Some more information:

    for LoginActivity:
    
    ScreenOrientation = ScreenOrientation.Portrait, MainLauncher = true, NoHistory = true)]         
    
    For MainActivity:
    
    LaunchMode = Android.Content.PM.LaunchMode.SingleTask,
    WindowSoftInputMode = SoftInput.AdjustPan,
    ScreenOrientation = ScreenOrientation.Portrait,
    ConfigurationChanges=
        Android.Content.PM.ConfigChanges.Orientation |
        Android.Content.PM.ConfigChanges.ScreenSize |
        Android.Content.PM.ConfigChanges.Keyboard |
        Android.Content.PM.ConfigChanges.KeyboardHidden)]
    
  • KevinSkreiKevinSkrei USMember ✭✭

    I'm not sure how your authentication works but you could possibly save the session in some sort of storage (ie. SharedPreferences). If the app is still alive and the user opens the MainActivity, in your OnResume() method you could check if the user has a valid session. If they do not have a valid session, simply start the LoginActivity. Otherwise, you have the information you need and let them use the MainActivity.

  • TedRogersTedRogers USMember ✭✭✭✭

    @KevinSkrei‌ thanks for the reply. Late yesterday I decided to not fight city hall and just take what Android gives me and do exactly what you said.

Sign In or Register to comment.