A.java
public class A extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(A.class.getName(), "OnCreate");
Intent intentB = new Intent(this, B.class);
intentB.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
startActivity(intentB);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(A.class.getName(), "onActivityResult");
}
}
B.java
public class B extends Activity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(B.class.getName(), "OnCreate");
Intent imagesIntent = new Intent(Intent.ACTION_GET_CONTENT);
imagesIntent.setType("image/*");
Intent openGalleryIntent = Intent.createChooser(imagesIntent, "pic");
startActivityForResult(openGalleryIntent, 2);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.d(B.class.getName(), "onActivityResult");
Log.d(B.class.getName(), data.getData().toString());
}
}
AndroidMenifest.xml
<uses-sdk android:minSdkVersion="8" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".A"
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="B"></activity>
</application>
The problem is after selecting image from gallery, onActivityResult() method of class B class does not execute.
Though if intentB.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY) is removed from intentB instance then onActivityResult() of class B executes fine.
This is the correct behavior. When you select FLAG_ACTIVITY_NO_HISTORY as the flag while calling the next activity. The child activity is removed from the stack and hence once you move out it would simply finish.
Reference
The question is why do you even want to use that flag?