Search code examples
javaandroidandroid-intentandroid-activityresultset

How to set results from next activity to previous activity in android studio


I have 2 activities one main and other contacts from main i am going to contact activity to select contact but when i set main activity after selecting contacts it recreates the main activity like new

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    String clicktemplate = arrayListplayer.get(i).getTitle1();
    Toast.makeText(ContactsSelect.this ,arrayListplayer.get(i).getTitle1(), Toast.LENGTH_SHORT).show();
    Intent intent = new Intent(ContactsSelect.this, PlanSMS.class);
    intent.putExtra("key_clicktemplate1", clicktemplate);
    startActivity(intent);


}

Here is my code I am starting new activity here using intent and pass clicktemplate variable but when i select another contact second time the first one disappears


Solution

  • use startActivityForResult

    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        String clicktemplate = arrayListplayer.get(i).getTitle1();
    
        Intent intent = new Intent(ContactsSelect.this, PlanSMS.class);
        intent.putExtra("key_clicktemplate1", clicktemplate);
        startActivityForResult(intent,1933);
    }
    

    example : Use onactivityresult android