Chronicle
Chronicle

Reputation: 1645

Android - onActivityResult ignores stored byte

I have an activity that started another activity with startActivityForResult. In that other activity I changed a byte, and then I return to the original activity, storing the changed byte in an Intent before calling finish().

Second activity:

public void goBack(View backButton){
    Intent previousPage = new Intent();
    System.out.println("open " + currentIndex);
    previousPage.putExtra("language", currentIndex);
    setResult(RESULT_OK, previousPage);
    finish();
}

First Activity:

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == RETURN_REQUEST_CODE) {
        if (resultCode == RESULT_OK) {
            Intent i = getIntent();
            currentIndex = i.getByteExtra("language", (byte)0);

            System.out.println("onactvityiresult " + currentIndex);
        }
    }
}

The byte was originally 0. I changed it to 1 in the second activity. System output however is:

10-09 19:00:34.519    9669-9669/com.example.admin.ghost I/System.out﹕ open 1
10-09 19:00:34.566    9669-9669/com.example.admin.ghost I/System.out﹕ onactvityiresult 0

If the byte is originally 1 and I change it to 0 in the second activity, the output is:

10-09 19:10:53.034  13437-13437/com.example.admin.ghost I/System.out﹕ open 0
10-09 19:10:53.331  13437-13437/com.example.admin.ghost I/System.out﹕ onactvityiresult 1

If I don't change the byte in the second activity, it correctly shows 0 and 0, or 1 and 1.

It is as if the First Activity keeps its original byte no matter what. How can I get the new byte passed to the First Activity?

Upvotes: 0

Views: 35

Answers (1)

Emma
Emma

Reputation: 9308

data, the argument of onActivityResult, is holding values from setResult(RESULT_OK, previousPage).

Upvotes: 1

Related Questions