I'm trying to get the resultCode to be OK inside my onActivityResult function. However, it keeps coming back as 0. I have spent several days on this, and can't figure out why it doesn't work. Here's my code. If anybody can help me, I'll be very grateful, Thanks.
My Activity1 class:
private class MyTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... urls) {
// process
return result;
}
@Override
protected void onPostExecute(String result) {
Intent i = new Intent(Activity1.this, Activity2.class);
i.putExtra("Value1", "This value one for ActivityOne ");
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivityForResult(i, REQUEST_CODE);
textView.setText(result);
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE) {
// do something
}
}
My Activity 2 class:
@Override
public void finish() {
Intent data = new Intent();
data.putExtra("returnKey1", "return 1");
setResult(RESULT_OK, data);
super.finish();
}
My manifest:
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".Activity1"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Activity2"
android:label="@string/app_dialog_name"
android:launchMode="singleTop"
android:excludeFromRecents="true"
android:taskAffinity=""
android:theme="@android:style/Theme.Dialog">
</activity>
</application>