本文介绍了Android的旋转造成NullPointerException异常时捕获照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在menifest |keyboardHidden方向configChanges =:

我使用的机器人。但它仍然刷新我的活动。这里是我的menifest活动标记。

 <活动
    机器人:名字=com.paksoft.people.MiActivity
    机器人:标签=@字符串/ APP_NAME
    机器人:configChanges =方向| keyboardHidden
    机器人:screenOrientation =画像
    机器人:windowSoftInputMode =adjustPan>
< /活性GT;


解决方案

这有可能是 ACTION_IM​​AGE_CAPTURE 意图推出将推动你的活动内存不足。参见例如: Android startCamera给我空意图和......它毁了我的全局变量?

在这种情况下,的onCreate()您的活动之前所谓的onActivityResult()。你应该prepare你的活动重新初始化本身,可能使用的onSaveInstanceState(捆绑)

请注意,该决定是否关闭活动,或保持在后台,取决于超出你的控制系统的整体状态。

PS:的android:configChanges 因为活动不被破坏的系统响应方向开关(这不能用发生属性无关机器人:screenOrientation =肖像),但由于系统资源被启动相机应用fullfill的 ACTION_IM​​AGE_CAPTURE 意图倒掉

I am using android:configChanges="orientation|keyboardHidden" in menifest. But still its refresh my activity. Here is my activity tag in menifest.

<activity
    android:name="com.paksoft.people.MiActivity"
    android:label="@string/app_name"
    android:configChanges="orientation|keyboardHidden"
    android:screenOrientation="portrait"
    android:windowSoftInputMode="adjustPan" >
</activity>
解决方案

It's possible that launching of ACTION_IMAGE_CAPTURE intent will push your activity out of memory. See for example: Android startCamera gives me null Intent and ... does it destroy my global variable?

In this situation, onCreate() of your activity is called before onActivityResult(). You should prepare your activity to reinitialize itself, probably using onSaveInstanceState(Bundle).

Note that the decision whether to shut down the activity, or keep it in background, depends on the overall system state that is beyond your control.

PS: android:configChanges attribute is irrelevant because the activity is destroyed not as response of the system to orientation switch (and this cannot happen with android:screenOrientation="portrait"), but because the system resources are drained by launching the Camera app to fullfill the ACTION_IMAGE_CAPTURE intent.

这篇关于Android的旋转造成NullPointerException异常时捕获照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-01 00:20