安卓打印"connection timeout"在 Loopj 中超时时



android我发现了更多,但没有得到解决方案。。

当loopj中发生超时时,我想打印超时消息。。

遵循我使用的超时代码。private static final int DEFAULT_TIMEOUT=15*1000;

private static AsyncHttpClient client = new AsyncHttpClient();
public static void setTimeOutTime() {
    client.setTimeout(DEFAULT_TIMEOUT);
    System.out.println("timeout");
}
    try {
        response = client.newCall(request).execute();
        jsonObj = new JSONObject(response.body().string());
    } catch (IOException e) {
        mActivity.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                if (getStatus() == Status.RUNNING) {
                    cancel(true);
                    if(!hiddenDialog) {
                        if (pDialog.isShowing())
                            pDialog.dismiss();
                    }
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(mActivity);
                builder.setTitle("Timeout error")
                        .setMessage("Sorry server doesn't response!nCheck your internet connection and try again.")
                        .setCancelable(true)
                        .setPositiveButton("Try again", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int id) {
                                Log.d(TAG, "load again");
                            }
                        }).setIcon(R.drawable.ic_dialog_alert_dark);
                AlertDialog alert = builder.create();
                alert.show();
            }
        });
    } catch (JSONException e) {}

编辑对于您的情况,它应该是相同的方式

mActivity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      // make toast
    }
});

相关内容

  • 没有找到相关文章

最新更新