您的位置:首页 > 移动开发

处理phonegap(cordova) application error the connection to the server was unsuccessful的错误

2015-07-06 11:25 597 查看

android 在log中提示TimeOut Error后,应用程序弹出application error

the connection to the server was unsuccessful 的错误的处理方法

第一步

找到项目中res/xml目录下的config.xml,把你的外网的域名地址添加到配置中

<access origin="http://example.com" /> <!--allow any secure requests to example.com -->

第二步

在activity的onCreate方法中加入一行代码

Java代码







public void onCreate(Bundle savedInstanceState) { [color=red]super.setIntegerProperty("loadUrlTimeoutValue", 60000); [/color] super.onCreate(savedInstanceState); super.loadUrl(AppSetting.WEBSERVICE_LOGIN); }
public void onCreate(Bundle savedInstanceState)
{
[color=red]super.setIntegerProperty("loadUrlTimeoutValue", 60000); [/color]
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)这个钩子方法。例如:

Java代码







if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){ //横向 setContentView(R.layout.file_list_landscape); }else{ //竖向 setContentView(R.layout.file_list); }
if(newConfig.orientation==Configuration.ORIENTATION_LANDSCAPE){
//横向
setContentView(R.layout.file_list_landscape);
}else{
//竖向
setContentView(R.layout.file_list);
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: