Android crashing after camera Intent

后端 未结 8 1394
半阙折子戏
半阙折子戏 2020-12-04 15:13

I have an app published and one of the fundamental features is to allow the user to take a picture, and then save that photo in a specific folder on their External Storage.

8条回答
  •  春和景丽
    2020-12-04 15:39

    I suspect 3 posible problems may have created your issue:

    1. Some devices return null when you call extras.get("data"); in onActivityResult method so your problem may be a NullPointerException. To solve this, you need to pass the exact URI location to tell the camera app where you want it to store and use it in onActivityResult to retrieve the image as a Bitmap.

    2. Some other devices return a full size Bitmap when extras.get("data"); in onActivityResult. If the bitmap is too large that can result in an OutOfMemmoryError, so maybe you need to decode your image in a smaller size to not take so much memmory heap. This two links can help you in this situation:

      http://developer.android.com/training/displaying-bitmaps/load-bitmap.html

      BitmapFactory OOM driving me nuts

    3. Maybe your activity is destroyed by the GC so you have to use onSavedInstanceState and onRestoreInstanceState to save your Activity's data. See the answer of this previous post for more information.

    I don't know if you already have dealt with these issues.

    Hope that helps:)

提交回复
热议问题