0

i heve one pojo class name contact

i open new activity for edit it

using this

Intent iEditContact = new Intent(JsonParseActivity.this, EditContatctActivity.class);
            iEditContact.putExtra(Constant.intent_key_edit_contact, contact);
            startActivityForResult(iEditContact, Constant.edt_contect_request_code);

i received that contact using this

if (iContact != null && iContact.hasExtra(Constant.intent_key_edit_contact)) {
        contact = iContact.getParcelableExtra(Constant.intent_key_edit_contact);

after i updte its name and number and other details...i want send again that pojo to my main activity and refresh recyclerview

how to do this with help of OnActivityResult() for without create new activity again

and how to retrive that list again in my mainactivtiy

BiRjU
  • 733
  • 6
  • 23

1 Answers1

1

How to retrieve that List again in my mainactivtiy ?

Well , you can use a BroadcastReceiver to receive it back to the 1st Activity , have a look..

In 1st Activity

make a field variable of broadcastReceiver

 BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
       Contact contact;
        if(intent.getExtras()!=null) {
           contact = intent.getParcelableExtra(Constant.intent_key_edit_contact);
    }
};

And in onResume register the receiver !!

@Override
public void onResume() {
    super.onResume();
    LocalBroadcastManager.getInstance(context).registerReceiver(broadcastReceiver,new IntentFilter("receive_contact"));        
}

And in 2nd activity after making modification to the contact object

 Intent intent = new Intent("receive_contact");
 intent.putExtra(Constant.intent_key_edit_contact, contact);
 LocalBroadcastManager.getInstance(context).sendBroadcast(intent);
Santanu Sur
  • 10,997
  • 7
  • 33
  • 52