onActivityResult returned from a camera, Intent null

前端 未结 7 748
执念已碎
执念已碎 2020-12-06 04:41

I follow the instruction on Camera on Android dev site

I just start the Camera Intent, not build my own camera.

The sample code to handle result return afte

7条回答
  •  执笔经年
    2020-12-06 05:37

    Use @KJ50's solution, and use savedInstanceState to make sure you don't get a null.

    /**
         * Here we store the file url as it will be null after returning from camera
         * app
         */
        @Override
        protected void onSaveInstanceState(Bundle outState) {
            super.onSaveInstanceState(outState);
    
            // save file url in bundle as it will be null on screen orientation
            // changes
            outState.putParcelable("file_uri", fileUri);
        }
    
        @Override
        protected void onRestoreInstanceState(Bundle savedInstanceState) {
            super.onRestoreInstanceState(savedInstanceState);
    
            // get the file url
            fileUri = savedInstanceState.getParcelable("file_uri");
        }
    

提交回复
热议问题