0

android I finding more but none of get solution..

when occur time out in loopj , I want print Time-out message..

Follow code for time-out which I used. 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");
}
Manish
  • 67
  • 8

1 Answers1

0
    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) {}

EDIT for your case it should be the same way

mActivity.runOnUiThread(new Runnable() {
    @Override
    public void run() {
      // make toast
    }
});
Pavel Zorin
  • 331
  • 6
  • 17