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 8343125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T05:57:51+00:00 2026-06-09T05:57:51+00:00

I want to have a user profile system in an app; this app has

  • 0

I want to have a user profile system in an app; this app has absolutely no sensitive data. I know how to do a secure log in as far as protecting the user password/username etc. But here is my question… once the login confirms that the username/password combo is correct, can I do this:

Use Sharedpreferences to set a login variable from 0 to 1. When the user logs out, it goes back to 0.
So anytime there is a function in the app that needs to check if the user is logged in, it just checks the state of this preference variable.

Is this a secure way of doing it? Or is there a better way?

(Normally in PHP I use session variables, not sure what the Android equivalent is.)

  • 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-09T05:57:53+00:00Added an answer on June 9, 2026 at 5:57 am

    Don’t use shared preferences, there are too many things that can go wrong, e.g. your app FCs or is killed by Android and has no chance to update them.

    You can override the Application class and use a static value, boolean perhaps, to indicate that the user is logged in.

    Here’s some pseudo code showing how to override the Application. It’s similar to a global variable but don’t overdo this and put all your data here 😉

    public class MyApp extends Application{
    
        public static boolean isUserLoggedIn = false;
        ...
    
    public void userLogin(){
    
       MyApp.isUserLoggedIn = true;
       ...
    
    public void userLogout(){
    
       MyApp.isUserLoggedIn = false;
       ...
    
    }
    

    Because the field is static and initialised to false, everytime your app starts, you can guarantee that it’s false. The only way it can ever be true is if it’s set in your app in code.

    You also need to add the extended class to your manifest:

    <application android:name=".MyApp" 
      ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to integrate chargify to my rails app. I have user object and
I have a mini blog app, and a reply system. I want to list
I need some help on creating a user profile system. I want it to
Does MySQL have a user profile system where I can associate permissions and rights
I want to create an User in test class with system Administrator profile. The
I want to have a delete user link in a normal Activerecord table, but
i have user control, which i render on several views. i want to show
I have a UITextView and I want have two buttons. When the user taps
I have a user database which I want the admin to be able view
I have two User Controls already created now I want to use one as

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.