[android-developers] Problem in Asynctask Execution in standby mode
Hi friends, I am using AsyncTask concept to download data from server. private class DownloadTask extends AsyncTaskVoid,Void,String { private ProgressDialog progressDialog; @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(ActivityTab.this); progressDialog.setProgress(10); progressDialog.setSecondaryProgress(32); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage(Downloading...); progressDialog.show(); } protected String doInBackground(Void... params) { String result= ; result = download(); return result; } protected void onPostExecute(String result) { if(progressDialog.isShowing()) progressDialog.dismiss(); Toast.makeText(getApplicationContext(), +result.toString(),Toast.LENGTH_LONG).show(); } } in download button click i called new DownloadTask().execute(); This is working well. the thing is if device goes to standby mode (Screen goes off) while showing this downloading.. progressbar mean my application getting force closed. it says like IllegalStateException. how to solve this probelm? it is there any way to prevent screen from locking untill complete this download process? please help me. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Problem in Asynctask Execution in standby mode
Async Task are UI Threads, probably that's the reason.. try creating Threads from any bound Services to perform the download and retreive the download status from service and update that in the UI whenever required.. On Thu, Jan 19, 2012 at 7:17 PM, sktniran sktniranjanad...@gmail.comwrote: Hi friends, I am using AsyncTask concept to download data from server. private class DownloadTask extends AsyncTaskVoid,Void,String { private ProgressDialog progressDialog; @Override protected void onPreExecute() { super.onPreExecute(); progressDialog = new ProgressDialog(ActivityTab.this); progressDialog.setProgress(10); progressDialog.setSecondaryProgress(32); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.setMessage(Downloading...); progressDialog.show(); } protected String doInBackground(Void... params) { String result= ; result = download(); return result; } protected void onPostExecute(String result) { if(progressDialog.isShowing()) progressDialog.dismiss(); Toast.makeText(getApplicationContext(), +result.toString(),Toast.LENGTH_LONG).show(); } } in download button click i called new DownloadTask().execute(); This is working well. the thing is if device goes to standby mode (Screen goes off) while showing this downloading.. progressbar mean my application getting force closed. it says like IllegalStateException. how to solve this probelm? it is there any way to prevent screen from locking untill complete this download process? please help me. -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Problem in Asynctask Execution in standby mode
On Thu, Jan 19, 2012 at 7:47 AM, sktniran sktniranjanad...@gmail.comwrote: my application getting force closed. it says like IllegalStateException. how to solve this probelm? What's the stack trace? it is there any way to prevent screen from locking untill complete this download process? Maybe, but that should not be necessary. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] Problem in Asynctask Execution in standby mode
Yes there is some thing called Wake Lock which you need to acquire and release as per your need On Thu, Jan 19, 2012 at 8:00 PM, TreKing treking...@gmail.com wrote: On Thu, Jan 19, 2012 at 7:47 AM, sktniran sktniranjanad...@gmail.comwrote: my application getting force closed. it says like IllegalStateException. how to solve this probelm? What's the stack trace? it is there any way to prevent screen from locking untill complete this download process? Maybe, but that should not be necessary. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
[android-developers] problem with AsyncTask
Hi, I was wondering if someone could help me with my asynctask? I have a problem with onPostExecute and onCancelled. onPostExecute seems to be skipped everytime I run the asynctask, the file downloads, no problem, but the dialog is still there. As for the cancel button, it doesn't seem to reach onCancelled. Can anyone wee what I'm doing wrong? /André protected class DownloadTask extends AsyncTaskContext, Integer, Void{ private Dialog dialogD; private ProgressBar downloadBar; private ImageButton cancel; OnClickListener listen = new OnClickListener() { @Override public void onClick(View v) { if(v == cancel) { downloadTask.cancel(true); } } }; @Override protected void onPreExecute() { super.onPreExecute(); // Context mContext = getApplicationContext(); dialogD = new Dialog(SilverFTP.this); dialogD.setContentView(R.layout.silver_ftp_downloading); dialogD.setTitle(Downloading...); TextView info = (TextView) dialogD.findViewById(R.id.download_info); info.setText(fileName); downloadBar = (ProgressBar) dialogD.findViewById(R.id.download_bar); cancel = (ImageButton) dialogD.findViewById(R.id.cancel_download); cancel.setOnClickListener((OnClickListener) this); dialogD.show(); logg.append(onPreExecute + \n); Log.i(makemachine, onPreExecute()); } @Override protected Void doInBackground(final Context... params) { try { InputStream stO = new BufferedInputStream(client.retrieveFileStream(fileToUse), client.getBufferSize()); OutputStream stD = new FileOutputStream(placeToPaste); while (ftpTotal ftpSize) { Util.copyStream(stO, stD, client.getBufferSize(), CopyStreamEvent.UNKNOWN_STREAM_SIZE, new CopyStreamAdapter(){ public void bytesTransferred(long totalBytesTransferred, int bytesTransferred, long streamSize) { double tempProgress = (((double)totalBytesTransferred / (double)ftpSize) * 100.0); int progress = (int) tempProgress; publishProgress(progress); } }); } client.completePendingCommand(); } catch (IOException e) { logg.append(Download IOExc, download() + \n); e.printStackTrace(); } return null; } protected void onProgressUpdate(final Integer... values) { downloadBar.setProgress(values[0]); Log.i(makemachine, onProgressUpdate(): + String.valueOf(values[0])); } @Override protected void onCancelled() { super.onCancelled(); downloadTask.dialogD.dismiss(); } @Override protected void onPostExecute(Void v) { logg.append(onPostExecute + \n); downloadTask.dialogD.dismiss(); } } -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] problem with AsyncTask
On Fri, Sep 10, 2010 at 9:56 AM, André pha...@hotmail.com wrote: Can anyone wee what I'm doing wrong? Best typo ever. Also, I'm very confused on how you've coded this up. It's declared like an AsyncTask, but the code executes as if it's an Activity. I'm assuming this is an inner class? If so, then this: cancel.setOnClickListener((OnClickListener) this); would be trying to add the AsyncTask as an OnclickListener, not the Activity. Furthermore, you've declared listen as the listener that cancels the dialog, but never actually use it ... I would suggest you move the Task to it's own class and pass anything it needs in the arguments. - TreKing http://sites.google.com/site/rezmobileapps/treking - Chicago transit tracking app for Android-powered devices -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en
Re: [android-developers] problem with AsyncTask
Maybe you meant something like: cancel.setOnClickListener(new OnClickListener() { public void onClick() { cancel(true); }); -- You received this message because you are subscribed to the Google Groups Android Developers group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en