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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T04:00:51+00:00 2026-06-14T04:00:51+00:00

Apology for another newbie question. I have this block of code in my MainActivity

  • 0

Apology for another newbie question. I have this block of code in my MainActivity should check the users and returns an appropriate activity based on the if else statement. Problem is that it skips the if block and I can’t figure out why. All I know is that the getID function works fine on other classes. Thank you for reading this.

public class MainActivity extends Activity {

    UserFunctions userFunctions;

    @Override
    public void onCreate(Bundle savedInstanceState) {

        userFunctions = new UserFunctions();

        super.onCreate(savedInstanceState);        
        setContentView(R.layout.main);        

        UserFunctions fn = new UserFunctions();
        String id = fn.getID(getApplicationContext());

        if("100".equals(id)){

            Intent in = new Intent(getApplicationContext(), AdminActivity.class);           
            startActivity(in);          
            finish();

        }else{

            Intent in = new Intent(getApplicationContext(), UserActivity.class);                        
            startActivity(in);      
            finish();

        }
    }
}

UserFunction Class

/* Get user ID from DatabaseHandler */
    public String getID(Context context) {
        String id = "";
        DatabaseHandler db = new DatabaseHandler(context);
        Cursor cursor = db.getUserID();

        if(cursor != null) {
            while(cursor.moveToNext()) {
                id = cursor.getString(0);
            }
        } else {
            id = "";
        }

        cursor.close();
        db.close();
        return id;
    }

DatabaseHandler Class

/* Get user ID from the database */
    public Cursor getUserID() {
        String qry = "SELECT id FROM " + TABLE_LOGIN;
        SQLiteDatabase db = this.getReadableDatabase();     
        Cursor cursor = db.rawQuery(qry, null);     
        return cursor;

    }
  • 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-14T04:00:52+00:00Added an answer on June 14, 2026 at 4:00 am

    Your getID() method always returns the ID of the last user in the database. This user is not id==”100″ since your if statement is evaluating to false.

    In getUserID, you select all records in the login table. Then:

    if(cursor != null) {
        while(cursor.moveToNext()) {
            id = cursor.getString(0);
        }
    } else {
        id = "";
    }
    

    if there are any users, this will return the ID of the last one, if there are no users, it will return “”.

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

Sidebar

Related Questions

First, I apology for this newbie question. I'm new in Objective C and OpenCV
First of all I would like apology if this question has already been answered,
Please let me preface this question with an apology. I am very new to
I have an ImageButton, which should contain the text. For this I use LayerDrawable
First off, an apology as I am sure this is question's answer is quite
Let me know if I have to make this more concise, if you don't
Firstly, an apology for the length of this post. If brevity is the soul
I have been trying different solutions for this problem without success. Problem is this:
My Question is little bit bigger so apology for that. Now my problem is
My apology for such a noob question. On my hosting server, there are two

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.