[Android_Bug]处理PhoneGap Application Error: "The connection to the server was unsuccessful.(file:///android_asset/www/index.html)"的错误

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);    

  }   

posted @ 2014-05-31 16:54  It's_Lee  阅读(5016)  评论(0编辑  收藏  举报