-1

I have a database where i have Unique id, Email id and Password. Im storing using SQlite database. I've to get the cursor which stores the result of the query, i have got the cloumn index of each cloumn, appended it using StringBuffer, but i dont know how to get those values in the other class? please help. here is my code for Adapter class:

public String getData(String email,String pwd)
{
    StringBuffer buffer=new StringBuffer();
    SQLiteDatabase db =sciHelper.getWritableDatabase();

    Cursor cursor = db.rawQuery("SELECT _id FROM " + SciHelper.TABLE_NAME + " WHERE email=? AND password=?", new String[]{email, pwd});
    while(cursor.moveToNext())
    {
        int index1=cursor.getColumnIndex(SciHelper.UID);
        int index2=cursor.getColumnIndex(SciHelper.EMAIL);
        int index3=cursor.getColumnIndex(SciHelper.PASSWORD);
        String cid=cursor.getString(index1);
        String mail=cursor.getString(index2);
        String mailpass=cursor.getString(index3);
        buffer.append(cid +" "+mail+" "+mailpass+"\n");
     }
   return buffer.toString();
}

code at login class:

public void checkTable(View view) {
    email2 = emaillog.getText().toString();
    pass2 = passlog.getText().toString();
    String data = sciDataBaseAdapter.getData(email2, pass2);
    String[] values=data.split("\\");

    String cid=values(0);
    if (TextUtils.isEmpty(email2)) {
        emaillog.setError("Enter Email Id");
        passlog.setError("Enter Password");
    }

        //   if (email1 != null) {
        Intent intent=new Intent(this,ResultActivity.class);
        startActivity(intent);
        Message.message(this, "Login succesful");
    } else {
        Message.message(this, "Invalid username/ or register");
    }
  }
}
Arya
  • 1,729
  • 3
  • 17
  • 35
Sayyaf
  • 316
  • 1
  • 4
  • 12
  • Possible duplicate of [Passing data from one activity to another in Android](http://stackoverflow.com/questions/5497502/passing-data-from-one-activity-to-another-in-android) – Nigam Patro Nov 27 '15 at 09:55

2 Answers2

1

When calling the ResultAcitvity

Intent intent=new Intent(this,ResultActivity.class);
intent.putExtra("key","value");
startActivity(intent);

and on ResultActivity, inside onCreate() method write

Intent intent=getIntent();
String value=intent.getStringExtra("key");
String[] values = value.split(" ");
String cid=values[0];
String mail=values[1];
String mailpass=values[2];
Nigam Patro
  • 2,760
  • 1
  • 18
  • 33
  • i have appended the values and returned them through string buffer, i want to get that data and split the appeneded data and want to get cid,mail, pass separately. so that i can store them in some variable. Intent is not the answer i'm looking for ,thanks tough – Sayyaf Nov 27 '15 at 10:06
  • @Sayyaf is this answer working as per your requirement. – Nigam Patro Nov 27 '15 at 10:19
  • @Sayyaf what is the status? – Nigam Patro Nov 27 '15 at 11:30
0
public void checkTable(View view) {
email2 = emaillog.getText().toString();
pass2 = passlog.getText().toString();
String data = sciDataBaseAdapter.getData(email2, pass2);
String[] values=data.split("\\");

String cid=values(0);
if (TextUtils.isEmpty(email2)) {
    emaillog.setError("Enter Email Id");
    passlog.setError("Enter Password");
}

    //   if (email1 != null) {
 Bundle bundle=new Bundle();
 b.putStringArray(some_key, values);
    Intent intent=new Intent(this,ResultActivity.class);
    intent.putExtra(bundle);
    startActivity(intent);
    Message.message(this, "Login succesful");
} else {
    Message.message(this, "Invalid username/ or register");
}
}

and in your next activity get that using.

Bundle extras = getIntent().getExtras();
String[] some_variable= extras.getString("some_key");
farhan patel
  • 1,490
  • 2
  • 19
  • 30