I have this code: class AttemptLogin extends AsyncTask {
    @Override
    protected void onPreExecute() {
        super.onPreExecute();
        pDialog = new ProgressDialog(MyAkan.this);
        pDialog.setMessage("Attempting login...");
        pDialog.setIndeterminate(false);
        pDialog.setCancelable(true);
        pDialog.show();
    }
    @Override
    protected String doInBackground(String... arg0) {
        int success;
        String idnumber = etIdnumber.getText().toString();
        String password = etPassword.getText().toString();
        try {
            // Building Parameters
            List<NameValuePair> params = new ArrayList<NameValuePair>();
            params.add(new BasicNameValuePair("idnumber", idnumber));
            params.add(new BasicNameValuePair("password", password));
            JSONObject json = jsonParser.makeHttpRequest(LOGIN_URL, "POST",
                    params);
            success = json.getInt(TAG_SUCCESS);
            if (success == 1) {
                Log.d("Login Successful!", json.toString());
                Intent i = new Intent("com.gpplsmje.mac.akan.AKANMENU");
                String id = json.getString(TAG_IDNUMBER);
                i.putExtra("idnumber", id);
                finish();
                startActivity(i);
                return json.getString(TAG_MESSAGE);
            } else if (success == 0) {
                Log.d("Login Failure!", json.getString(TAG_MESSAGE));
                return json.getString(TAG_MESSAGE);
            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return null;
    }
    @Override
    protected void onPostExecute(String file_url) {
        // TODO Auto-generated method stub
        pDialog.dismiss();
        if (file_url != null) {
            Toast.makeText(MyAkan.this, file_url, Toast.LENGTH_LONG).show();
        }
    }
}
This app connects to a server and returns encoded JSON data. Whenever I test it on a local server on my machine, it works fine. It connects fine with the server. But when I turn off my server and use the app, the app loads but stops after a minute or so of login attempt. Is there a way to time the progress for maybe 20sec maximum, and then if it consumes the time it must dismiss the progressdialog and return to the main activity?
Thanks.
 
     
    