Last active
August 29, 2015 14:13
-
-
Save eneim/59df18b4f92065e7d409 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private class DownloadTask extends AsyncTask<String, Void, String> { | |
@Override | |
protected String doInBackground(String... urls) { | |
HttpResponse response = null; | |
HttpGet httpGet = null; | |
HttpClient mHttpClient = null; | |
String s = ""; | |
// check if the url is invalid | |
if (urls == null || urls.length == 0) | |
return null; | |
try { | |
if(mHttpClient == null) { | |
mHttpClient = new DefaultHttpClient(); | |
} | |
httpGet = new HttpGet(urls[0]); | |
response = mHttpClient.execute(httpGet); | |
s = EntityUtils.toString(response.getEntity(), "UTF-8"); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return s; | |
} | |
@Override | |
protected void onPostExecute(String... strings) { | |
// show your dialog here | |
// please do check null first | |
if (strings == null || strings.length == 0) | |
return; | |
new AlertDialog.Builder(PrintDemo.this) | |
.setTitle("Message") | |
.setMessage(strings[0]) | |
.setPositiveButton(android.R.string.ok, null) | |
.setCancelable(false) | |
.create() | |
.show(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment