Android的方向 - 问题同意图(摄像头) [英] android orientation - issues with intents (camera)

查看:303
本文介绍了Android的方向 - 问题同意图(摄像头)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个有趣的...

Here is an interesting one...

我有我写运行Android 2.3.3及以上的设备的应用程序。

I have an application I am writing for devices running android 2.3.3 and above.

它具有通过一个Intent调用摄像头主要活动。

It has a main activity which calls the camera via an Intent.

如果用户点击一个按钮,启动摄像头;然后拍照;随后点击完成返回到主活动 - 该应用程序工作正常,并在主要活动的ImageView的显示新的图片

If the user clicks a button to launch the camera; then takes a picture; then clicks "Done" to return to the main activity - the application works fine and displays the new picture in an imageview on the main activity.

然而,如果用户使用纵向的主要活动;然后点击按钮,打开相机意图和改变方向为横向;然后单击完成返回到主活动 - 该应用程序崩溃。

however, if the user uses the main activity in portrait orientation; then clicks the button to open the camera intent and changes the orientation to landscape; then click done to return to the main activity - the application crashes

但后来......但是,如果用户使用纵向的主要活动;然后点击按钮,打开相机意图和改变方向为横向;然后改变方向单击Done之前回纵向(在相机中)返回到主活动 - 那么应用程序将继续正常运行。

but then...however, if the user uses the main activity in portrait orientation; then clicks the button to open the camera intent and changes the orientation to landscape; then changes the orientation back to portrait (in the camera) before clicking done to return to the main activity - then the application continues to run normally.

东西我曾尝试:
我已经改变清单文件中强制应用程序(主要活动),在纵向取向(我也删除了这一点)
我曾试图处理活动的重画它从相机意图返回添加了此行的主要活动:

Stuff I have tried: I have changed the manifest file to force the application (main activity) to be oriented in portrait (I have also removed this) I have added this line to the main activity in an attempt to handle the re-drawing of the activity on it return from the camera intent:

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

在调试窗口中我得到的错误说明空指针异常 - 我想这是因为的意见是改变方向时的图像传入除非方向是相同的有人离开时,作为以后不再有

In the debug window I get errors describing nullpointer exceptions - I think this is because the views are no longer there after an orientation change for the image to be passed into unless the orientation is the same as when it was left.

我有点坚持这样会AP preciate一些建议。

I'm a bit stuck so would appreciate some advice.

推荐答案

在您的屏幕方向的变化,你的活动被破坏,并在新的方向重新创建。使活动的生命周期内获得了一个参考的变量将不再是指什么,如果你再尝试访问对象,他们是指无需重新分配他们的价值观,你会得到一个 NullPointerException异常

When your screen orientation changes, your Activity is destroyed and recreated in the new orientation. So any variables that gained a reference during the life of the Activity will no longer refer to anything, and if you then try to access objects they refer to without re-assigning them values, you'll get a NullPointerException.

该方法的onSaveInstanceState()用来保存配置更改之间的临时数据。这将创建传递给的onCreate一个Bundle()在活动重新启动

The method onSaveInstanceState() is used to save temporary data between configuration changes. This creates a Bundle which is passed to onCreate() when the Activity starts up again.

在没有任何code,我不知道这是否是你的问题,但它是值得一试。

Without any code, I don't know if that's your problem, but it's worth a look.

请参阅的http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges有关详细信息,(比我提供,无疑更准确的信息)。

See http://developer.android.com/reference/android/app/Activity.html#ConfigurationChanges for more information (and more accurate information than I've provided, no doubt).

这篇关于Android的方向 - 问题同意图(摄像头)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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