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>
En Problem nach der Auswahl eines Bildes aus der Galerie wird die Methode onActivityResult() der Klasse B nicht ausgeführt.
Wenn jedoch intentB.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
aus der Instanz intentB entfernt wird, wird onActivityResult() der Klasse B ordnungsgemäß ausgeführt.