The code below retrieves multiple selected contacts and stores it in the form of ArrayList but once I close the application and open the selected contact list is removed ,so the data should be stored so that once I close and open the app the data remains until the data is removed. Can anyone please help me to store the ArrayList values using shared preference .
private void chooseContact() {
Intent intentContactPick = new Intent(MainActivity.this,ContactsPickerActivity.class);
MainActivity.this.startActivityForResult(intentContactPick,CONTACT_PICK_REQUEST);
}
@Override
public void onActivityResult(int requestCode,int resultCode,Intent data){
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == CONTACT_PICK_REQUEST && resultCode == RESULT_OK){
ArrayList<Contact> selectedContacts = data.getParcelableArrayListExtra("SelectedContacts");
String display="";
for(int i=0;i<selectedContacts.size();i++){
display += (i+1)+". "+selectedContacts.get(i).toString()+"\n";
}
contactsDisplay.setText("Selected Contacts : \n\n"+display);
}
}
}
the below code is the ArrayList which holds the selected contact values.
ArrayList<Contact> selectedContacts = data.getParcelableArrayListExtra("SelectedContacts");