0

I am making a mailing app. What I want to do is open list chooseContactsActivity from composeMailActivity, select some contacts and click add to send them back to composeMailActivity. First thing I did was that standard passing between activities where I passed a string, and the correct string was passed and recognized in composeMailActivity. Then I added arrayList of strings - of contact ids. In chooseContactsActivity it is recognized correctly when debugging, but in the composeMailActivity it returns null.

Some of the answers I tried include: 1, 2, 3, 4, 5...

ChooseContactsActivity:

addButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            ArrayList<String> selectedIds = adapter.selectedIds;

            String text = "abc";

            Intent intent = new Intent();
            intent.putStringArrayListExtra("contacts_added", selectedIds);
            setResult(RESULT_OK, intent);
            finish();
        }
});

ComposeMailActivity:

 @Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
            ArrayList<String> get_contacts = getIntent().getExtras().getStringArrayList("contacts_added");
        }
    }
}
Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Banana
  • 2,435
  • 7
  • 34
  • 60

2 Answers2

4

I think try to get "contacts_added" form "data". Instead of calling getIntent() try

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    if (requestCode == 1) {
        if (resultCode == RESULT_OK) {
            ArrayList<String> get_contacts = data.getExtras().getStringArrayList("contacts_added");
        }
    }
}

Hope this will solve your problem.

Durga M
  • 534
  • 5
  • 17
4

You should use the data Intent in onActivityResult(int requestCode, int resultCode, Intent data) instead of getIntent() like this

if (resultCode == RESULT_OK) {
            ArrayList<String> get_contacts = data.getExtras().getStringArrayList("contacts_added");
        }
tamtom
  • 2,474
  • 1
  • 20
  • 33