Utman Alami
Utman Alami

Reputation: 131

how to add data in multiple activities

I am here again to ask for help, now i will give details on my problem hoping someone can solve it : in the first activity onClick the method insert is executed

 public class ActivityUn extends Activity {

 DBAdapter db = new DBAdapter(this); 
  public void  ajouter(View v) {

    db.open();
      Toast.makeText(getApplicationContext(), "Données enregistrées", Toast.LENGTH_LONG).show();



        db.insertMENAGE(rm_1ts,rm_2ts,rm_3ts);


           db.close();
      }

the second activity code is :

   public class ActivityDeux  extends Activity {


    DBAdapter db = new DBAdapter(this);
     public void  ajouter(View v) {
        db.open();


        db.insertMENAGE2(id,a16,b17,rm_18_1ts,rm_18_2ts,c19,d20,e21);
        db.close();                     
        } 

and here the two methods insert and update ...

 public long insertMENAGE(String Region, String Provence_prefecture ,StringCommune_Arrondissement) {
  ContentValues initialValues = new ContentValues();
      initialValues.put(col_Region,Region);
      initialValues.put(col_Provence_prefecture ,Provence_prefecture);
      initialValues.put(col_Commune_Arrondissement,Commune_Arrondissement);
       return db.insert(MENAGE,null, initialValues);
  }

In the second activity I will update the same table by completing remaining columns in the row :

  public void insertMENAGE2(int id, int a16, int b17) {
   ContentValues values = new ContentValues();
      values.put(col_Type_habitat,a16);
      values.put(col_Statut_occupation ,b17);
      db.update(MENAGE,values,_id+"="+id, null);
}

Now , I want to indicates the id ( primary key ) of the row in table which is Inserted Last ,

I already looked for solutions but they are not adapted to my situation, since i have other activities updating the same table

And i need to indicates each time that the id concerned is the last one inserted.

Thanks

Upvotes: 1

Views: 181

Answers (1)

wvdz
wvdz

Reputation: 16641

To save primitive data for use over multiple activities, your best bet is SharedPreferences.

Upvotes: 1

Related Questions