Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8750167
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:49:11+00:00 2026-06-13T12:49:11+00:00

In my application, i have made login activity as the main launcher. When user

  • 0

In my application, i have made login activity as the main launcher. When user opens app first time user need to enter credentials to go to main activity. At the time user logs in, i have saved some information that main activity need in Preferences.
Now what i want is, when ever user opens app again, assume user has not logged out, user should be sent directly to main activity with the help of information saved in the preferences.

Below is the code in login activity which creates new session.

 if (res.carExists != true)
            {
                MyMessageBox.SetAlertBox("Opps!!!!!!!!", "This Car Number Was Wrong!!!!", "OK", m_context);
            }
            else
            {
                string carType = res.carType;
                string seatNum = res.numOfSeats.ToString();
                // MainActivity act = new MainActivity( result.driverId );
                session = new SessionManger(m_context);
                session.createLoginSession(result.driverId.ToString());
                var mact = new Intent(m_context, typeof(MainActivity));
                mact.PutExtra("driverID", result.driverId.ToString());
                MyMessageBox.SetAlertBox("Comfirm!", "Your car is a: " + carType + " with " + seatNum + " seats??", "Yes", "No", mact, m_context);
        }

Below is the code for Session Manager which saves the user information in login.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Android.App;
using Android.Content;
using Android.OS;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.Preferences;

namespace NorthStar.Driver
{
    public class SessionManger
    {
        ISharedPreferencesEditor editor;
        ISharedPreferences pref;

        // Context
        Context _context;

        // Shared pref mode
        int PRIVATE_MODE = 0;

        // Sharedpref file name
        private static readonly String PREF_NAME = "AndroidHivePref";

        // All Shared Preferences Keys
        private static readonly String IS_LOGIN = "IsLoggedIn";

        // User name (make variable public to access from outside)
        public static readonly String KEY_NAME = "driver";


        // Constructor
        public SessionManger(Context context)
        {
            this._context = context;
            pref = _context.GetSharedPreferences(PREF_NAME, Android.Content.FileCreationMode.Private);
            editor = pref.Edit();
        }

        public void createLoginSession(String driverID)
        {
            // Storing login value as TRUE
            editor.PutBoolean(IS_LOGIN, true);

            // Storing name in pref
            editor.PutString(KEY_NAME, driverID);

            editor.Commit();
        }

        public void  checkLogin()
        {
            if (!this.isLoggedIn())
            {
                Intent i = new Intent(_context, typeof(Activity1));
                i.AddFlags(ActivityFlags.ClearTop);
                i.SetFlags(ActivityFlags.NewTask);
                _context.StartActivity(i);
            }


        }

        public string getDriver()
        {
            return pref.GetString(KEY_NAME, "");
        }

        public Boolean isLoggedIn()
        {
            return pref.GetBoolean(IS_LOGIN, false);
        }


    }
}

Can somebody give me some hint how can i direct user to main activity with the help of saved informationin Shared Preferences.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T12:49:12+00:00Added an answer on June 13, 2026 at 12:49 pm

    As you are saving some value in shared preference when user logs in, next time when app opens, check for that shared preference value in Login activity(before doing login stuff). If its true(say for example), start main activity(finish login activity so that user should not come back to login activity after pressing back button) else continue with login activity. When user logs out, again replace shared preference value to false so that when next time app opens control should come to Login activity first.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made an application which allows a user to login using their facebook
I have made a web application that uses master page for Login & Logout
I need to run the application that I have made in Xcode on my
I have made a MVC application that uses the built-in ASP.NET login functions. It
I have dotnetnuke application and I made a custom login module. And everything works
I have a application (made in Delphi) that contains a Authentication system (login &
hi I have a problem I made an application based on apples sample app
I'm writing an Android application which requires the user to login. I have a
I have made a java application and have packed it into an executable jar
I have made a flash application and in this flash application I have included

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.