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");
        }
    }
}

2 Answers 2

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");
        }
Sign up to request clarification or add additional context in comments.

1 Comment

That is it, I will accept your answer as soon as I am able to :D
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.

2 Comments

It works, but I accepted tomtom's answer because he answered a few seconds before, but I voted up. Thank you for your answer
No problem. Happy that I could able to help you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.