Parse.com在Android中没有互联网可用性

Parse.com在Android中没有互联网可用性,android,parse-platform,timeout,connection-timeout,timeoutexception,Android,Parse Platform,Timeout,Connection Timeout,Timeoutexception,我正在使用parse.com开发Android应用程序。我正在使用此代码检查互联网可用性,它工作正常。但是,如果我打开互联网并发出任何解析请求,例如“检查用户名”,并且在该请求期间,如果我停止4G或wifi,则不会检查互联网可用性并使应用程序崩溃 我想做一些事情,比如如果我没有从解析中得到答案,那么它应该给我超时功能 private void createUserinfo() { if(isNetworkConnected){ final ParseObject userI

我正在使用parse.com开发Android应用程序。我正在使用此代码检查互联网可用性,它工作正常。但是,如果我打开互联网并发出任何解析请求,例如“检查用户名”,并且在该请求期间,如果我停止4G或wifi,则不会检查互联网可用性并使应用程序崩溃

我想做一些事情,比如如果我没有从解析中得到答案,那么它应该给我超时功能

private void createUserinfo() {

  if(isNetworkConnected){
        final ParseObject userInfo = new ParseObject("UseIfo");
        userInfo.put("medicote", "");
        userInfo.put("user", ParseUser.getCurrentUser());
// If i turn the Internet On and and the request, during sending if i again stop
// internet then it will not notifies me like TIME OUT Request or something like this.
        userInfo.saveInBackground(new SaveCallback() {

            ParseUser  user = ParseUser.getCurrentUser();
        @Override
            public void done(ParseException e) {
                if (e == null) {
                    user.put("info", userInfo);
                    user.saveInBackground();
                    finishMe();
                }
            }
        });
} else{
      return "No Internet Available";
}
    }


private boolean isNetworkConnected() {
    ConnectivityManager cm = (ConnectivityManager) 
            getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo ni = cm.getActiveNetworkInfo();
    if (ni == null) {
        // There are no active networks.
        return false;
    } else
        return true;
    }
}

将您的
发送代码
放入

try{
//here
} catch(Exception e) {
      e.printStackTrace();
      Toast.makeText(getApplicationContext(), "Network error", Toast.LENGTH_SHORT).show();
}

除了在开始解析请求之前检查Internet/网络可用性外,您还可以使用此技术创建超时功能,以便请求不会无休止地继续: