Android 三星 Tab3 上的 sendUserActionEvent() mView==null
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23016155/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
sendUserActionEvent() mView==null on Samsung Tab3
提问by user3524254
I am trying to preview an image after capturing it using camera from inside my app, I am sure the path is not null but I am receiving this error in this line of code Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options);
and there is no image view. Note: I tested the code on another device (not Samsung) and it works.
我正在尝试使用相机从我的应用程序内部捕获图像后预览图像,我确定路径不为空,但我在这行代码中收到此错误Bitmap bitmap = BitmapFactory.decodeFile(fileUri.getPath(),options);
并且没有图像视图。注意:我在另一台设备(不是三星)上测试了代码并且它有效。
回答by A.J
I found a fix for this problem. Unfortunately, on some Samsung devices there is a problem with the built-in camera app that it causes screen rotation which leads to restarting your activity. For that mView
becomes null. This happens also with other intents in samsung, not only in the camera. To fix it, you have to add this line in your manifest under your activity:
我找到了解决此问题的方法。不幸的是,在某些三星设备上,内置相机应用程序存在问题,它会导致屏幕旋转,从而导致重新启动您的活动。因为那mView
变为空。这也发生在三星的其他意图中,而不仅仅是在相机中。要修复它,您必须在您的活动下的清单中添加以下行:
android:configChanges="orientation|screenSize"
Google mentions in the documentation
谷歌在文档中提到
Beginning with Android 3.2 (API level 13), the "screen size" also changes when the device switches between portrait and landscape orientation. Thus, if you want to prevent runtime restarts due to orientation change when developing for API level 13 or higher (as declared by the minSdkVersion and targetSdkVersion attributes), you must include the
"screenSize"
value in addition to the"orientation"
value. That is, you must declareandroid:configChanges="orientation|screenSize"
. However, if your application targets API level 12 or lower, then your activity always handles this configuration change itself (this configuration change does not restart your activity, even when running on an Android 3.2 or higher device).
从 Android 3.2(API 级别 13)开始,当设备在纵向和横向之间切换时,“屏幕尺寸”也会发生变化。因此,如果在为 API 级别 13 或更高级别(如 minSdkVersion 和 targetSdkVersion 属性所声明的)进行开发时,要防止由于方向更改而导致运行时重新启动
"screenSize"
,则除了该"orientation"
值之外,还必须包括该值。也就是说,您必须声明android:configChanges="orientation|screenSize"
. 但是,如果您的应用程序面向 API 级别 12 或更低级别,则您的 Activity 始终会自行处理此配置更改(此配置更改不会重新启动您的 Activity,即使在 Android 3.2 或更高版本的设备上运行时)。
回答by KyleCrowley
In regards to the sendUserActionEvent() mView==null
, it is a know bug with Samsung devices (see thisand this).
关于sendUserActionEvent() mView==null
,这是三星设备的一个已知错误(参见这个和这个)。
If it works on non-Samsung devices, then it is not your fault, it is Samsung's.
However, you should try and find a workaround if you can.
Again, it isn't your fault, it is a bug with TouchWiz.
如果它适用于非三星设备,那么这不是您的错,而是三星的错。
但是,如果可以,您应该尝试找到解决方法。
同样,这不是您的错,而是 TouchWiz 的错误。
回答by lukaspp
I have struggled with this error for days, this happens because Samsung Camera app is by default in Landscape mode.
我已经为这个错误苦苦挣扎了好几天,这是因为三星相机应用程序默认处于横向模式。
If you start camera app from an activity in Portrait mode, when it comes back from Landscape it calls automatically again OnCreate, that's why your path is null.
如果您从纵向模式的活动启动相机应用程序,当它从横向返回时,它会再次自动调用 OnCreate,这就是您的路径为空的原因。
I solved this by adding a static counter into the activity if it is equal to 0 app call oncreate and did it all, if it is greater than 0 loads only layout.
我通过在活动中添加一个静态计数器来解决这个问题,如果它等于 0 app call oncreate 并完成所有操作,如果它大于 0 只加载布局。
回答by Bhrigu
Yes, that's correct.
对,那是正确的。
What AJ has mentioned is the solution:
AJ提到的是解决方案:
android:configChanges="orientation|screenSize"
It also solves another issue that arises due to calling the OnCreateView method every time the phone is rotated; helps prevent different edit fields from reverting to their original values, provided you have used onSaveInstance()
to store your initial values. You can refer to this video here for that-
它还解决了由于每次手机旋转时调用 OnCreateView 方法而出现的另一个问题;有助于防止不同的编辑字段恢复为其原始值,前提是您已用于onSaveInstance()
存储初始值。你可以在这里参考这个视频——
https://www.youtube.com/watch?v=_K_qlNluW38&index=67&list=PLHs_NFdr_LaHmEh7hV-wPyS-gKnAVPzBU
https://www.youtube.com/watch?v=_K_qlNluW38&index=67&list=PLHs_NFdr_LaHmEh7hV-wPyS-gKnAVPzBU