OnCreate and onRestoreInstanceState (Bundle) not called after startActivityForResult

advertisements

I'm trying to load an image from gallery.
This is the onCreate() :

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_gallery_picture);

    mThis = this;
    mImageCache = new TakingPictureActivityCacheMngr(this);

    initUi();

    if (savedInstanceState == null) {
        openGallery();
    }
}

Here is the onSaveInstanceState():

@Override
protected void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    // save file url in bundle as it will be null on scren orientation
    // changes
    outState.putParcelable("file_uri", mFileUri);
    if (com.isee.spot.toolkit.Config.IS_DEBUG) {
        Log.d(TAG, "Instance was saved.");
    }
}

On restore : (never called)

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
    super.onRestoreInstanceState(savedInstanceState);

    // get the file Uri
    mFileUri = savedInstanceState.getParcelable("file_uri");
}

The onCreate() is never called after opening the gallery, onDestroy() is called right when the gallery is opened and so it the onSaveInstanceState().

Here is the activity declaration in the manifest :

<activity
    android:name=".GalleryPictureActivity"
    android:configChanges="orientation|keyboard|keyboardHidden"
    android:screenOrientation="portrait" >
</activity>

I overloaded the onActivityResult() :

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);
    // if the result is loading image from gallery
    if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
    ...


Here is the answer, The activity itself was correct.
The problem is with the activity which start it, I used : galleryPic.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); Apparently this cause the onActivityResult(int, int, Intent) not be called.
Leaving this just for the chance of someone getting same behavior. Thank you for trying to help, I guess you had no chance.