Android:调用相机意图后活动被破坏 [英] Android: Activity getting Destroyed after calling Camera Intent

查看:21
本文介绍了Android:调用相机意图后活动被破坏的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个活动(A1,A2).A1 调用 A2,从 A2 调用相机意图,如下所示

I am having two Activities (A1 , A2). A1 calls A2 and from A2 i am calling the camera intent as below

launchIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
launchIntent.putExtra(MediaStore.EXTRA_OUTPUT,photoPath);   
startActivityForResult(launchIntent,CAMERA_REQUEST);

它打开相机,我可以拍照.但是一旦我单击保存按钮(s3 中的勾选按钮),问题就会出现,我的 onActivityResult 没有被调用,而是调用了 A2 的 onDestroy 方法.我在 onActivityResult fn 中几乎没有逻辑要完成.

It opens the camera, and i can take the picture. But the Problem arises once i click the save button (tick button in s3), my onActivityResult is not called instead A2's onDestroy method is called. I have few logics to be done in the onActivityResult fn.

我在 Stackoverflow 中阅读了一些关于此的帖子,但我无法从中获得有用的输出.我的第二个活动(A2)有这样的清单

I had read some post in Stackoverflow regarding this but i couldnt get useful output from that.I have my manifest like this for my second Activity(A2)

android:configChanges="keyboardHidden|orientation|locale"
android:screenOrientation="portrait

注意:在 HTC One X 中,我的 onActivityResult fn 被调用,但在我的 S3 中,第二个 Activity(A2) 被破坏

Note: In HTC One X my onActivityResult fn is getting called, but in my S3 second Activity(A2) is getting destroyed

请分享您对此的看法.提前致谢

Plz share ur thoughts on this. Thanks in Advance

推荐答案

我遇到了同样的问题.我会发疯但最终我找到了解决方案 此处.问题是当您单击相机的保存"按钮时,活动调用更改方向方法,它将销毁并重新创建.尝试设置

i had the same problem.i will be crazy but finally i have found a solution here. the issue is that when you click on "save" button of the camera the activity call change orientation method and it will destroy and recreated. try to set

android:configChanges="orientation|screenSize"

在 android 清单中(不仅是 android:configChanges="orientation" 因为正如建议的 此处,它不适用于 API 级别 13 或更高版本).

in android manifest (not only android:configChanges="orientation" because as suggest here, it not work for API level 13 or higher).

它可以防止破坏活动,它对我有用.

it prevent to destroy activity,it work for me.

这篇关于Android:调用相机意图后活动被破坏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆