1

I have the following application Where the user have to signup with (Email ,pass ,Hight ,Weight).. then he will login with Email and pass -> choose Calculate BMI option -> Here in this activity i want to display the result of BMI calculation for the logged in user .. is their any way to retrieve the (Weight,Hight) in the BMIActivity or i have to pass it with intent ?

I used SQLite Database Helper.

I just want a guider how to think about this.

Below is the homepage code for the button

public void onClick(View view){

    if(view==BMI){

      cursor = db.rawQuery("SELECT * FROM " + DatabaseHelper.R_TABLE_NAME + " WHERE " + DatabaseHelper.R_COL_10 + "=? AND " + DatabaseHelper.R_COL_11 + "=?" , new String[]{Weight,Hight});
       if(cursor!=null){
            if (cursor.getCount()>0) {
                cursor.moveToNext();
                String Weight = cursor.getString(cursor.getColumnIndex(DatabaseHelper.R_COL_10));
                String Hight = cursor.getString(cursor.getColumnIndex(DatabaseHelper.R_COL_11));
                Intent i = new Intent(HomepageNActivity.this, BMIActivity.class);
                i.putExtra("Weight",Weight);
                i.putExtra("Hight",Hight);
                startActivity(i);
            }

        }
    }

Below is the BMI calculation activity

 protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_bmi);
    openHelper=new DatabaseHelper(this);
    db = openHelper.getWritableDatabase();
    TextView TBMI= (TextView) findViewById(R.id.textView13);
      cursor = db.rawQuery("SELECT * FROM " + DatabaseHelper.R_TABLE_NAME + " WHERE " + DatabaseHelper.R_COL_10 + "=? AND " + DatabaseHelper.R_COL_11 + "=?" , new String[]{Weight,Hight});
      if(cursor!=null){
        if (cursor.getCount()>0) {
            cursor.moveToNext();
            String Weight = cursor.getString(cursor.getColumnIndex(DatabaseHelper.R_COL_10));
            String Hight = cursor.getString(cursor.getColumnIndex(DatabaseHelper.R_COL_11));
        }}
Markus Kauppinen
  • 3,025
  • 4
  • 20
  • 30
shahad
  • 21
  • 4
  • In both instances you are saying (*example using 10 for the weight and 11 for the hight*) select the row from the database where the weight = 10 and the hight = 11, get the weight and hight (which will be 10 and 11). You already know the values that you are retrieving. So there is no need to retrieve the already known values. – MikeT Dec 10 '18 at 11:30

2 Answers2

0

If only two values are needed that is height and width so, you can also use shared Preference for that to store on login button click after some validation check and on BMIActivity and yes you can also pass the values with intent as per your requirement you can directly display value, no need to use SQLite database.

PJain
  • 526
  • 2
  • 14
0

While the user signs up you can keep his/her BMI in a seperate column of DB table whose primary key is email of user and when user Sign In you can fetch that record on basis of email.