2014-04-23 131 views
0

我正在缩小范围并解释为尽可能简单, 主要活动启动异步任务。Android NullPointerException在屏幕方向更改

当方向改变onCreate()被召回所以Async创建一次获得。所以在onPreExecute()我锁定我的方向,并在onPostExecute()我释放锁定方向。通过这种方式,如果Async任务已经开始,另一个任务实例将永远不会被创建。

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

该怎么办?任何帮助

请问方法或主线程完成后onCreate()得到重新叫......或者是瞬时的,因为一旦方向得到改变

谢谢

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

<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> 
+0

任何代码将有助于诊断问题 –

+0

发布您的清单文件和错误跟踪。 –

+0

您也可以在清单中禁用应用程序重新启动。此外,长时间运行的任务可以通过服务来处理。 – atok

回答

5

发现我的解决方案...

android:configChanges="orientation" does not work with fragments如果要防止因方向改变运行时重新启动了API级别13或更高版本(由minSdkVersiontargetSdkVersion宣布开发时

属性),除了orientation值之外,还必须包含screenSize值。也就是说,您必须声明android:configChanges="orientation|screenSize"

0

为清单中的该特定活动添加android:configChanges =“orientation”。

+0

我试图在configChanges中设置方向,onConfigurationChanged()没有被调用,onCreate被一直调用。 – harshal