I started child activity from parent activity using startActivityForResult . After performing the necessary functions in the child activity, I set the result using setResult . But I do not get the result from parent activity from child activity.
Here is my code.
This is how I call my child activity from parent activity.
Intent i = new Intent(MainActivity.this, Child.class);
i.putExtra("ID", intID);
i.putExtra("aID", aID);
i.putExtra("myMsg", myMsg);
startActivityForResult(i, 1);
This is how I set the result from my child activity.
@Override
public void onBackPressed() {
super.onBackPressed();
Intent resultInt = new Intent();
resultInt.putExtra("Result", "Done");
setResult(Activity.RESULT_OK, resultInt);
finish();
}
This is my onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 1) {
if (resultCode == Activity.RESULT_OK) {
if(data!=null) {
Toast.makeText(MainActivity.this, "Data received", Toast.LENGTH_SHORT).show();
}
}
}
}
Here, when I check resultCode == Activity.RESULT_OK , gives false. And I also checked for an intent passed outside this if condition, and its return value is null.
<activity
android:name=".MainActivity"
android:label="Main"
android:parentActivityName=".MainPage"
android:theme="@style/AppTheme.NoActionBar">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.mydomain.mydomain.MainPage" />
</activity>
<activity
android:name=".Child"
android:label="Child"
android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme1">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="org.mydomain.mydomain.MainActivity" />
</activity>
- .