Android camera photo comes back null

后端 未结 2 1082
悲&欢浪女
悲&欢浪女 2020-12-21 23:29

In my android app I employ a camera activity which sometimes works and sometimes doesn\'t. About 30% of the time the uri set up to store the photo comes back with a null va

2条回答
  •  醉梦人生
    2020-12-22 00:23

    Thanks to CommonsWare I resolved the issue by implementing a onSaveInstance State. This should be required information on any android camera documentation as you lose the global variables whenever you change the camera's orientation.

           @Override
    public void onSaveInstanceState(Bundle savedInstanceState) {
        // Save the user's current game state
        savedInstanceState.putParcelable("myURI", imageUri);
        // Always call the superclass so it can save the view hierarchy state
        super.onSaveInstanceState(savedInstanceState);
    }
    
    public void onRestoreInstanceState(Bundle savedInstanceState) {
        // Always call the superclass so it can restore the view hierarchy
        super.onRestoreInstanceState(savedInstanceState);
        // Restore state members from saved instance
       imageUri = savedInstanceState.getParcelable("myURI");
    
    }
    

提交回复
热议问题