Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a sqlite database that the user can register to! I have successfully created a login form and when the login is successful (username & password match the database's) the user is redirected to another activity. What i want is in the activity that the user is redirected,
to display his entire database row (id,username, books,email,course, password, student name)!! Any ideas?? I would really appreciate if you could help me as this is the final task to complete my final year project..I use Android Studio!! I have created staff like Adapters database helpers ans cursorsThis is urgent!!!

Here is my database creation code:

SQL
static final String DATABASE_CREATE = "create table "+"LOGIN"+
        "( " +"ID"+" integer primary key autoincrement,"+ "USERNAME  varchar2," +
        "PASSWORD varchar2, COURSE varchar2, EMAIL varchar2, STUDENT_NAME varchar2); ";


Here is how I store data in the database:

Java
public void insertEntry(String userName,String password,String course,String email, String student_name)
{
    ContentValues newValues = new ContentValues();
    // Assign values for each row.
    newValues.put("USERNAME", userName);
    newValues.put("PASSWORD",password);
    newValues.put("COURSE", course);
    newValues.put("EMAIL",email);
    newValues.put("STUDENT_NAME", student_name);
 
    // Insert the row into your table
    db.insert("LOGIN", null, newValues);
    ///Toast.makeText(context, "Reminder Is Successfully Saved", Toast.LENGTH_LONG).show();
}


And finally here is the login that starts the new activity code:
C#
if(password.equals(storedPassword))
            {
                Toast.makeText(MyActivity.this, "Congrats: Login Successfull", Toast.LENGTH_LONG).show();
                dialog.dismiss();
                startActivity(new Intent(MyActivity.this, Login_home.class));
            }
            else
            {
                Toast.makeText(MyActivity.this, "User Name or Password does not match", Toast.LENGTH_LONG).show();
            }
Posted

1 solution

A walk through of the following code snippets:
1. in the LoginActivity:
// create a bundle object to store user's data
Bundle bundle = new Bundle();
// assign the values as key-value pairs
bundle.putString("username", username);
bundle.putString("email", email);
      
// create the intent
Intent i = new Intent(LoginActivity.this, NewActivity.class);
// assign the bundle to the intent
i.putExtras(bundle);
// finally start the new activity
startActivity(i);

2. in the NewActivity
//create a bundle object to store the extras
Bundle bundle=getIntent().getExtras();
//get the values by their keys
String username=bundle.getString("username");
String email=bundle.getString("email");
// do whatever you like to the data
 
Share this answer
 
v3
Comments
Member 11522447 22-Mar-15 9:13am    
Thanks a lot for your reply :) The public void insertEntry (which holds the variables username and email) is in the LoginAdapter class which I call in the register Activity to register the user!! So when I create the Bundle in the login activity it cannot find the variables username and email!!
Peter Leow 22-Mar-15 9:30am    
Actually, when the user logs in successfully, you can send his username as an extra to the new activity, then in the new activity, retrieve his particulars from the sqlite based on his username.
To learn of the sqlite, read my article http://www.codeproject.com/Articles/816470/Handling-Input-and-Storage-on-Android#sqlite
Member 11522447 22-Mar-15 9:14am    
If you want I can send you my Java and XML code files with email to see for yourself what I mean!!
Peter Leow 22-Mar-15 9:33am    
That will come with a cost but defeats my purpose here. So no.
Member 11522447 22-Mar-15 9:35am    
Sorry for the continually asking but as you can see I am a beginner!! What would be a good way to pass the username to the new activity?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900