android-asynctask

InputStream from URL in AsyncTask

僤鯓⒐⒋嵵緔 提交于 2020-01-14 07:10:48
问题 Trying to get a file from URL into InputStream element (with AsyncTask) and then use it, but so far unsuccessful. Are the parameters right for AsyncTask? Can I check InputStream like I did in my code or is it wrong and it will always return null? Any other changes I should make? My code: String url = "https://www.example.com/file.txt"; InputStream stream = null; public void load() { DownloadTask downloadTask = new DownloadTask(); downloadTask.execute(url); if (stream == null) { //fail, stream

InputStream from URL in AsyncTask

非 Y 不嫁゛ 提交于 2020-01-14 07:10:22
问题 Trying to get a file from URL into InputStream element (with AsyncTask) and then use it, but so far unsuccessful. Are the parameters right for AsyncTask? Can I check InputStream like I did in my code or is it wrong and it will always return null? Any other changes I should make? My code: String url = "https://www.example.com/file.txt"; InputStream stream = null; public void load() { DownloadTask downloadTask = new DownloadTask(); downloadTask.execute(url); if (stream == null) { //fail, stream

Update TextView fields in onPostExecute()

两盒软妹~` 提交于 2020-01-14 06:47:36
问题 I'm parsing weather data in AsyncTask's doInBackground() method and storing parsed data in strings: protected Void doInBackground(Void... params) { ... Element element = (Element) list.item(i); if (element.getNodeName().equals("station_id")){ String stationId = element.getTextContent(); } else if (element.getNodeName().equals("observation_time") ){ String observationTime = element.getTextContent(); ... I have 2 TextViews in my UI. How do I update them in onPostExecute() with stationId and

How to asynchronous perform a httprequest and show the progress of downloading the response

江枫思渺然 提交于 2020-01-13 05:54:06
问题 I am trying to perform a http-get-request and show the download progress to the user. I am familiar with the concept of AsyncTask, I also know how to use URLConnection together with BufferedInputStream to download a file in pieces while showing a progress AND I know how to execute a http-get-request and receive a HttpResponse: HttpClient httpclient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(url); HttpResponse response = httpclient.execute(httpget); But I just cannot figure out

How to timeout Asynctask and dismiss ProgressDialog?

一个人想着一个人 提交于 2020-01-13 04:42:28
问题 I've got a problem and hope you can help me. I've got an Asynctask, which starts uploading data if I press a button in my mainactivity. It works fine except if I've got a slow internet connection. The Asynctask starts a progressdialog and if I've got a slow connection, Asynctask stops but the Progressdialog doesn't disappear because it never reached onPostExecute. Now I'm trying to implement a timeout but can't find a way, so that the progressdialog dismisses to do this. Here is my code:

Why does android logcat not show the stack trace for a runtime exception?

纵饮孤独 提交于 2020-01-12 12:49:09
问题 An android application that I am currently developing was crashing (fixed that), due to what should have raised an IndexOutOfBoundsException. I was accessing a string in the doInBackground method of a class that extends AyncTask, from the variable arguments parameter (ie String...). I was accidentally accessing index 1 (not 0) of a one element variable argument string (mildly embarrassing...). When the application first crashed I looked at my logcat, (and many times again to confirm that I

Where to “quit” with looper?

五迷三道 提交于 2020-01-12 09:45:08
问题 I have a problem with a looper. I call looper.prepare() , and after doing something it all works fine. But if I rotate the device I get an exception on the prepare. 07-12 16:40:09.760: E/activity(15809): java.lang.RuntimeException: Only one Looper may be created per thread I'm trying to quit the looper, but it doesn't do anything. Here is my AsyncTask: @Override protected String doInBackground(String... args) { try{Looper.prepare(); //here start the exception try { URL url = new URL(link);

Android - Stop AsyncTask when back button is pressed and return to previous Activity

╄→гoц情女王★ 提交于 2020-01-12 05:31:08
问题 I've an AsyncTask and I want it to stip execution when back button is pressed. I also want the app to return to the previous displayed Activity. It seems I've managed in stop the Task but the app doesn't return to the previous activity. Any ideas? This is an extract from my code private class MyTask extends AsyncTask<Void, Void, Void> implements OnDismissListener{ private boolean exception= false; @Override protected void onPreExecute(){ pd = ProgressDialog.show( IscrizioniActivity.this,

ASyncTasks blocking others

陌路散爱 提交于 2020-01-11 15:49:41
问题 I've 2 ASyncTasks, one retrieves a value from an httpPost and the other update some elements of the UI (including an listview). The problem is that since both ASyncTasks share the same background thread, if the network opperation start first and runs slow (due a bad network connectivity). The others background thread takes too much time making the app irresponsible. Since both ASyncTasks are independient is pretty stupid one to make wait the other. It would be more logical asynctasks

ASyncTasks blocking others

孤者浪人 提交于 2020-01-11 15:49:09
问题 I've 2 ASyncTasks, one retrieves a value from an httpPost and the other update some elements of the UI (including an listview). The problem is that since both ASyncTasks share the same background thread, if the network opperation start first and runs slow (due a bad network connectivity). The others background thread takes too much time making the app irresponsible. Since both ASyncTasks are independient is pretty stupid one to make wait the other. It would be more logical asynctasks