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

  • Home
  • SEARCH
  • 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 6213765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:45:22+00:00 2026-05-24T06:45:22+00:00

My Android app need the user to create an account to be able to

  • 0

My Android app need the user to create an account to be able to use the app. The account info is stored in SQLite database. When the application starts I check if the user has an account, if not I show a sign up activity for the user.

Now I get reports from users that they sometimes comes to the sign up activity even if they’ve already created an account. This happens when they’ve closed the application and reopen it again.

This is the code I’m using and I need to figure out what the problem might be:

//MyApplication.java
public class MyApplication extends Application {
    private DataBaseUtility dbu;
    public boolean hasAccount;  

    @Override
    public void onCreate() {
        super.onCreate();

        //Init sqlite database
        this.dbu = new DataBaseUtility(this);

        //This loads the account data from the database and returns true if the user has already created an account
        this.hasAccount = loadAccount();
    }

    public boolean loadAccount() {
        boolean loadedData = false;

        String query = "SELECT data FROM tblaccount WHERE tblaccount.deleted=0";
        Cursor cursor = this.dbu.getCursor(query);
        if (cursor != null) {
            while (cursor.moveToNext()) {
                loadedData = true;
            }
            cursor.close();
        }

        return loadedData;
    }
}

//MainActivity.java
public class MainActivity extends TabActivity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        MyApplication application = (MyApplication)getApplication();
        if (!application.hasAccount) {
            //Take the user to the sign up activity
        }
}

My idea is that maybe sometimes MainActivity.onCreate() runs before MyApplication.onCreate(). Can that be the case?

  • 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-05-24T06:45:23+00:00Added an answer on May 24, 2026 at 6:45 am

    In application‘s onCreate, you are checking if the user has an account and setting a boolean.

    You are checking in the MainActivity‘s onCreate if the user has an account through the application‘s boolean.

    application‘s onCreate() executing before MainActivity‘s onCreate() is always the case! It is impossible for a different execution path to occur and since application‘s onCreate() does not have a Runnable it is a 100% garantuee.

    Please make sure you’re DataBaseUtility does not have any Runnables.

    Anyway STILL there are several ways to reproduce the error! I will not state these now but you can know them when you see:

    SOLUTION

    MainActivity You have forgotten to update application.hasAccount upon successfull sign up~

    public class MainActivity extends TabActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            MyApplication application = (MyApplication)getApplication();
            if (!application.hasAccount) {
                //Take the user to the sign up activity
                //if(successful) application.hasAccount = true
            }
    }
    

    To avoid database exceptions

    I use this:

    REMARK It would be much better to use more strong persistent status saving for the database -i.e. SharedPreferences

    boolean isOpened = false;
    //When I need to open
    if(!isOpened){
        //open
        isOpened = true;
    }
    //When I need to close
    if(isOpened){
        //close
        isOpened = false;
    }
    
    onDestroy() {  //every onDestroy
        if(isOpened){
            //close
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I created a Twitter app I need user of my Android application to authorize
Android Calendar App I need to be able to implement a view similar to
I need to develop an android app that achieves the following: Create an activity
I'm creating an app that will need users to create an account. (Like Facebook
I am working on an application in android. Where I need to use menu
My android app project need to add a new function of saving the click
I'm building an Android app and I need to have two different themes for
I'm working with an existing Android app and I need to have a dynamically
I need to test my Android app for playing flash objects in the WebView.
I need table with editable cells for my Android app. Something like QTableWidget in

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.