Android 在为结果调用活动时,是否有合适的方法执行onRestoreInstanceState的等效操作?

Android 在为结果调用活动时,是否有合适的方法执行onRestoreInstanceState的等效操作?,android,onactivityresult,onrestoreinstancestate,Android,Onactivityresult,Onrestoreinstancestate,我当前正在从相机或图库检索照片,例如 Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI); startActivityForResult(i, RESULT_LOAD_IMAGE); 这很好用。当前活动的行为有点误导人 它调用onSaveInstanceState很好,但是当您在ActivityRe

我当前正在从相机或图库检索照片,例如

        Intent i = new Intent(Intent.ACTION_PICK,  MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                            startActivityForResult(i, RESULT_LOAD_IMAGE);
这很好用。当前活动的行为有点误导人


它调用onSaveInstanceState很好,但是当您在ActivityResult上得到回调时,它从未调用过RestoreInstanceState,现在我理解了生命周期,但这似乎违反了直觉。您真的必须知道onSaveInstanceState/onRestoreInstanceState是如何执行的,还是忽略这一点,在onPause/onResume中使用perm存储。我已经分别看到了onSaveInstanceState/onRestoreInstanceState在onPause/onResume之前的解释。因此,活动生命周期似乎不能真正处理这一问题。直观地说,您会认为,如果调用onSaveInstanceState,那么应该调用onRestoreInstanceState。在复杂的活动中,我几乎可以自己写了。处理这种情况的最佳方法是什么

执行在onRestoreInstanceState中要执行的操作,以恢复onActivityResult。因为onRestoreInstanceState是在您的活动被销毁时调用的,而不是在调用其他活动时调用的。在本例中,您称为startActivityForResult,您的活动为keep aliveYes,但startActivityForResult不调用onRestoreInstanceState,这使得我在onSaveInstanceState中调用startActivityForResult时所做的操作毫无用处。这不是我是否打电话给startActivityForResult的问题,我打了。它用于在SaveInstanceState上调用startActivityForResult的场景,基本上是无用的,因为它的计数器部分onRestoreInstanceState从未被调用。