I’m building an application where the first Activity starts another one by startActivityByResult. After some setting is done, I need to send the setting result back.
So I override the second Activity’s onPause() method, I get the intent, putExra, and send it back through setResult().
Back to the first Activity. onActivityResult has definitely been called. I got the resultCode set before, but the intent data is null. I can’t figure out what’s wrong.
Here’s my code:
The first Activity
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.e("page1", requestCode + "_");
Log.e("page1", resultCode + "_");
Log.e("page1", (data == null) + "_");
// if ((requestCode == 1) && (data != null)) {
if (data != null) {
String size = data.getStringExtra("size");
Log.e("switch", size + "_");
switch (size.charAt(0)) {
case '1': {
text.setTextSize(10);
}
break;
case '2': {
text.setTextSize(20);
}
break;
case '3': {
text.setTextSize(30);
}
break;
}
}
}
My second Activity
@Override
protected void onPause() {
Intent intent = getIntent();
Log.e("prefs", (intent == null) + "_");
intent.putExtra("size", size);
setResult(3, intent);
super.onPause();
}
I’ve tested in LogCat. In the second Activity. The intent about to be sent is definitely not null. But when it goes to the first Activity. Null just returned. This is driving me really crazy.
Can you try this.
you want to finish your activity in all the cases in pause manually and in back press automatically so it will be better to save your intent data in onDestroy