1

I have two activities and a database. I want to send the data from the first activity to the data base and then move to the next activity. I know this is wrong but it is the best I could find online, any other ways of doing it?

OnItemClickListener viewNeeds = new OnItemClickListener(){

    @Override
    public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
            long arg3) {
        // TODO Auto-generated method stub
        //create variable for database input
        feelingForDb = ((AdapterView<ListAdapter>) feelingsList).getSelectedItem().toString();
        Intent gotoNeeds=
                new Intent(FeelingsMain.this, Needs.class);
        startActivity(gotoNeeds);
    }
  • where is your database code? – yushulx Jul 22 '13 at 08:13
  • Use SQLITE ? http://developer.android.com/reference/android/database/sqlite/package-summary.html – An-droid Jul 22 '13 at 08:17
  • what exactly is the problem you are facing? Are you able to get `feelingForDb` from DB? If yes, then you can simply pass this string as part of `gotoNeeds` intent. Use `gotoNeeds.putExtra("some_identifier_name", feelingForDb);` and in the `Needs` class you will need to retrieve it using `getIntent().getStringExtra("some_identifier_name");` – Rajeev Jul 22 '13 at 08:19

1 Answers1

1

on First activity insert data to data base when its inserted start next activity

your insertData function of database class, should return long type data

like

long success = db.insert(tableName, null, values);
     return success;

than inside First Activity

if(longReturned>0)
{
//startActivity2 here
}
Tarsem Singh
  • 14,139
  • 7
  • 51
  • 71