Activity killed / onCreate called after taking picture via intent

你离开我真会死。 提交于 2019-11-27 03:39:42

Actually the camera causes the orientation change in your activity that is why your activity is being destroyed and recreated.

Add this in your manifest file it will prevent the orientation change and your activity will not get destroyed and recreated.

<activity
    android:name=".YourActivity"
    android:configChanges="orientation|keyboardHidden|screenSize"
    android:screenOrientation="portrait" >
</activity>

Fix the Orientation of your Activity/Application because when you back/finish() activity and at the same time you change orientation then activity refresh and restart again automatically.

It seems that there are phones that destroys the activity when importing an image, such as Galaxy S3. It is mentioned that if my app is in portrait mode it will happen because the images are in landscape mode. Thus, all the suggestions related to configChanges in the manifest file are not applicable to this situation.

What I ended up doing is instead of fighting the onDestroy of the activity (that caused the onActivityResult() of the fragment not to be called after onCreate()) was to implement onActivityResult() also in the activity itself and there I could get the image path. Then I passed that path to the fragment, once it is being created, for further processing. Of course I had to tell my app, once it is recreated, that it needs to go back to the calling fragmnet to process that image

Disable "Don't keep activities" Developer setting. Otherwise it will destroy the activity you are leaving.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!