android 在log中提示TimeOut Error后,應用程序彈出application error the connection to the server was unsuccessful 的錯誤的處理方法:
第一步
找到項目中res/xml目錄下的config.xml,把你的外網的域名地址添加到配置中
<access origin="http://example.com" />
第二步
在activity的onCreate方法中加入一行代碼
public void onCreate(Bundle savedInstanceState)
{
super.setIntegerProperty("loadUrlTimeoutValue", 60000);
super.onCreate(savedInstanceState);
super.loadUrl(AppSetting.WEBSERVICE_LOGIN);
}
第三步 禁止橫屏
方法:
在AndroidManifest.xml的activity(需要禁止轉向的activity)配置中加入android:screenOrientation=”landscape”屬性即可(landscape是橫向,portrait是縱向)
或者在屏幕切換的時候保存相應的活動狀態
因為android中每次屏幕方向切換時都會重啟Activity,所以應該在Activity銷毀前保存當前活動的狀態,在Activity再次Create的時候載入配置,那樣,進行中的操作就不會自動重啟了,要避免在轉屏時重啟activity,可以通過在androidmanifest.xml文件中重新定義方向(給每個activity加上android:configChanges=”keyboardHidden|orientation”屬性),並根據Activity的重寫onConfigurationChanged(Configuration newConfig)方法來控制,這樣在轉屏時就不會重啟activity了,而是會去調用onConfigurationChanged (Configuration newConfig)這個鈎子方法。
例如:
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
//橫向
setContentView(R.layout.file_list_landscape);
}else{
//豎向
setContentView(R.layout.file_list);
}