在改变屏幕方向的Andr​​oid NullPointerException异常 [英] Android NullPointerException on Screen Orientation Change

查看:130
本文介绍了在改变屏幕方向的Andr​​oid NullPointerException异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我缩小并解释那样简单就可以了,
主要活动将启动一个异步任务。

当方向改变的onCreate()记得这样异步创建一次收获。所以在上preExecute()我锁我的方向和 onPostExecute()我释放方向锁定。通过这种方式,如果异步任务已启动任务的另一个实例将永远不会创建。

另一个问题已经开始,在主要活动中本身 findViewById()返回null当我随意不断变化屏幕方向。在5-6尝试重新生产一次。

如何去对这个?任何帮助

确实的onCreate()获得重新调用方法或主线程完成后...或者是瞬时的,只要方向得到改变。

感谢您

---------------更新

 <应用
        机器人:allowBackup =真
        机器人:图标=@绘制/ ap_logo
        机器人:标签=@字符串/ APP_NAME
        机器人:主题=@风格/ AppTheme>
        <活动
            机器人:名字=agilepoint.android.mobilebpm.main.LoginActivity
            机器人:configChanges =方向
            机器人:标签=@字符串/ APP_NAME
            机器人:标志=@绘制/ menu_button
            机器人:windowSoftInputMode =adjustPan | stateHidden
            >
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.MAIN/>                <类机器人:名字=android.intent.category.LAUNCHER/>
            &所述; /意图滤光器>
            &所述;意图滤光器>
                <作用机器人:名字=android.intent.action.VIEW/>                <数据机器人:计划=HTTP/>
            &所述; /意图滤光器>
        < /活性GT;
 < /用途>


解决方案

发现我的解决方案...

<一个href=\"http://stackoverflow.com/questions/7139488/androidconfigchanges-orientation-does-not-work-with-fragments\">android:configChanges="orientation"不与片段工作

如果您对API级别开发时要因方向改变prevent运行时重新启动13或更高版本(由的minSdkVersion targetSdkVersion 属性),则必须包含除取向屏幕尺寸价值。也就是说,你必须声明的android:configChanges =方向|屏幕尺寸

I am narrowing down and explaining as simple as can, main activity initiates an async task.

When orientation change onCreate() is recalled so Async is created once gain. so in onPreExecute() i lock my orientation and in onPostExecute() i release lock on orientation. By this way if Async task has started another instance of task will never get created.

another issue has started, in main activity itself findViewById() returns null when i randomly keep changing the screen orientation. Re-producing once in 5-6 tries.

how to go on this? any help

Does onCreate() get re-called after completion of method or main thread... or is it instantaneous as soon as orientation get changed

Thank you

---------------updated

 <application
        android:allowBackup="true"
        android:icon="@drawable/ap_logo"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="agilepoint.android.mobilebpm.main.LoginActivity"
            android:configChanges="orientation"
            android:label="@string/app_name"
            android:logo="@drawable/menu_button"
            android:windowSoftInputMode="adjustPan|stateHidden" 
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.VIEW" />

                <data android:scheme="http" />
            </intent-filter>
        </activity>
 </application>

解决方案

Found my solution...

android:configChanges="orientation" does not work with fragments

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 declare android:configChanges="orientation|screenSize".

这篇关于在改变屏幕方向的Andr​​oid NullPointerException异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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