我目前正在从相机或相册中检索照片,例如
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
哪个工作正常。它是当前活动的行为,有点误导。
它调用onSaveInstanceState很好,但是当你获得onActivityResult的回调时,它永远不会调用onRestoreInstanceState,现在我理解了生命周期,但这似乎反直觉。你真的必须知道事情如何执行onSaveInstanceState / onRestoreInstanceState,或者你忽略它并在onPause / onResume中使用perm存储。我分别在onPause / onResume之前看到过onSaveInstanceState / onRestoreInstanceState的解释。所以似乎Activity生命周期并没有真正解决这个问题。直观地,您会认为如果调用onSaveInstanceState,则应调用onRestoreInstanceState。在复杂的活动中,我几乎准备好自己编写。处理这种情况的最佳方法是什么?