[android-developers] Repeating AsyncTasks t
I'm not sure if I'm going the right way about this.. but.. I have both username and password fields, as well as a login button. When the login button is clicked I grab both the username and password and attempt an online login. The authentication happens inside of an AsyncTask so I can display a ProgressDialog. If the users attempt to login failed, they should have another chance. But of course I'm unable to repeat an already Finished AsyncTask. What would be a canonical work around for this? I'm under the impression resetting a variable which contains an instance of the task and re-applying it would be a 'bad thing'. Regards, Lee -- 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 To unsubscribe, reply using remove me as the subject.
[android-developers] Repeating an AsyncTask
Hi guys, I have an Activity which uses Http based authentication to log a user into an online site. I'm using an AsyncTask to handle authentication in the background so I can display a ProgressDialog in the meantime. If the user login fails they should be given another chance. Of course, though, you cannot repeat an AsyncTask once it's finished. What would be the canonical way of doing so? I was going to hold a weak reference to an instance of the task and re-create it if I need to. What would be the suggested way? Regards, Lee -- 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 To unsubscribe, reply using remove me as the subject.
[android-developers] Re: adb cannot find my dev phone
Read the documentation: http://developer.android.com/guide/developing/device.html If it's a permissions issue try running `abd kill-server` followed by `adb devices` as root, if your device shows you can either leave it be, and switch back to a regular user and commence with debugging etc, or set up permissions which is discussed within the documentation. Regards, Lee On 14 Nov, 21:48, Antonio Si antonio...@gmail.com wrote: Hi, I just got my android dev phone, but when I invoke adb devices, it only shows: List of devices attached no permissions What does it mean? What is the problem and how should I fix it? Would appreciate any input. Thanks. Antonio. -- 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] Re: AsyncTask and ProgressDialog
Ahh! That makes total sense, I was trying to do more or less the same thing but it got tricky a there were a few flaws, this is great. I have a much better understanding of things now. Thanks On 11 Nov, 01:22, Lance Nanek lna...@gmail.com wrote: Here's a quick attempt at rewriting it without a static. Turned out more complex than I'd like. Pastebin version:http://pastebin.com/m7b8b184 Inline version: public class MyActivity extends Activity { private final static String LOG_TAG = MyActivity.class.getSimpleName (); private final static int DIALOG_ID = 1; private Task mTask; private boolean mShownDialog; @Override protected void onPrepareDialog(int id, Dialog dialog) { super.onPrepareDialog(id, dialog); if ( id == DIALOG_ID ) { mShownDialog = true; } } private void onTaskCompleted() { Log.i(LOG_TAG, Activity + this + has been notified the task is complete.); //Check added because dismissDialog throws an exception if the current //activity hasn't shown it. This Happens if task finishes early enough //before an orientation change that the dialog is already gone when //the previous activity bundles up the dialogs to reshow. if ( mShownDialog ) { dismissDialog(DIALOG_ID); Toast.makeText(this, Finished.., Toast.LENGTH_LONG).show(); } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Object retained = getLastNonConfigurationInstance(); if ( retained instanceof Task ) { Log.i(LOG_TAG, Reclaiming previous background task.); mTask = (Task) retained; mTask.setActivity(this); } else { Log.i(LOG_TAG, Creating new background task.); mTask = new Task(this); mTask.execute(); } } @Override public Object onRetainNonConfigurationInstance() { mTask.setActivity(null); return mTask; } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_ID: ProgressDialog dialog = new ProgressDialog(this); dialog.setMessage(Loading stuff..); dialog.setCancelable(true); return dialog; } return super.onCreateDialog(id); } private static class Task extends AsyncTaskVoid, Void, Void { private MyActivity activity; private boolean completed; private Task(MyActivity activity) { this.activity = activity; } @Override protected void onPreExecute() { activity.showDialog(DIALOG_ID); } @Override protected Void doInBackground(Void... unused) { try { Log.i(LOG_TAG, Background thread starting sleep.); Thread.sleep(15 * 1000); } catch (InterruptedException e) { Log.e(LOG_TAG, Thread interrupted:, e); } Log.i(LOG_TAG, Background thread finished sleep.); return null; } @Override protected void onPostExecute(Void unused) { completed = true; notifyActivityTaskCompleted(); } private void notifyActivityTaskCompleted() { if ( null != activity ) { activity.onTaskCompleted(); } } private void setActivity(MyActivity activity) { this.activity = activity; if ( completed ) { notifyActivityTaskCompleted(); } } } } On Nov 10, 5:41 pm,LeeJarvisljjar...@googlemail.com wrote: I've tried that, too. But again to no avail, nothing I do seems to work. I've tried using the callback features whilst also implementing weak references which also doesn't work. Once I change orientation, the progressDialog never disappears, it's
[android-developers] ListActivity searching
I realize there is many ways to search a through a list (you can just start type, or you can use the hardware search button to open the search dialog). I've seen in many applications there is a button to open the search dialog, as if you pressed the hardware search button. I've searched around like crazy but can't find anything regarding this. Could anyone point me in the right direction? Thanks -- 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] Re: ListActivity searching
Ahh perfect! Thanks Mark On Nov 11, 12:18 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: I realize there is many ways to search a through a list (you can just start type, or you can use the hardware search button to open the search dialog). I've seen in many applications there is a button to open the search dialog, as if you pressed the hardware search button. I've searched around like crazy but can't find anything regarding this. Could anyone point me in the right direction? Call startSearch() in your Activity: http://developer.android.com/reference/android/app/Activity.html#star...) You can see this in action here: http://github.com/commonsguy/cw-advandroid/tree/master/Search/Lorem/ -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, $35/Year -- 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] Async thread aborted after catching (all?) exceptions
I have the following code... @Override protected Void doInBackground(Void... unused) { Log.i(TAG, invoking background thread); try { mClient.get(http://thishostdoesntexist;); } catch (RuntimeException e) { mActivity.onTaskError(e.getMessage()); } catch (HttpResponseException e) { mActivity.onTaskError(e.getMessage()); } catch (ClientProtocolException e) { mActivity.onTaskError(e.getMessage()); } catch (UnknownHostException e) { mActivity.onTaskError(e.getMessage()); } catch (IOException e) { mActivity.onTaskError(e.getMessage()); } Log.i(TAG, exiting background thread); return null; } My mClient get method is a simple HttpClient execute with an output buffer to read the input stream, so it's very trivial. Everytime I execute this task UnknownHostException will be triggered which will in turn call onTaskError on my currect Activity, but I still get a RuntimeException, but I don't see why. Maybe it's because it's late and i've done about 12 hours of writing code so it's something simple I just can't see? What should I be looking for? Thanks in advance -- 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] Re: Async thread aborted after catching (all?) exceptions
So I've been sifting through example after example of android code, and I see most web requests don't actually catch that many exceptions, maybe because their path is hard coded so there is no room for user error? I'm still confused as the best way to exit my background task gracefully if my get() method raises an exception, at the moment getting anything but a force close just isn't happening On 11 Nov, 18:43, Lee Jarvis ljjar...@googlemail.com wrote: I have the following code... @Override protected Void doInBackground(Void... unused) { Log.i(TAG, invoking background thread); try { mClient.get(http://thishostdoesntexist;); } catch (RuntimeException e) { mActivity.onTaskError(e.getMessage()); } catch (HttpResponseException e) { mActivity.onTaskError(e.getMessage()); } catch (ClientProtocolException e) { mActivity.onTaskError(e.getMessage()); } catch (UnknownHostException e) { mActivity.onTaskError(e.getMessage()); } catch (IOException e) { mActivity.onTaskError(e.getMessage()); } Log.i(TAG, exiting background thread); return null; } My mClient get method is a simple HttpClient execute with an output buffer to read the input stream, so it's very trivial. Everytime I execute this task UnknownHostException will be triggered which will in turn call onTaskError on my currect Activity, but I still get a RuntimeException, but I don't see why. Maybe it's because it's late and i've done about 12 hours of writing code so it's something simple I just can't see? What should I be looking for? Thanks in advance -- 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] Re: Async thread aborted after catching (all?) exceptions
Yeah, my bad.. 11-11 21:47:01.811: INFO/InetAddress(797): Unknown host thishostdoesntexist.net, throwing UnknownHostException 11-11 21:47:02.270: ERROR/AndroidRuntime(797): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception 11-11 21:47:02.260: WARN/dalvikvm(797): threadid=15: thread exiting with uncaught exception (group=0x4001aa28) 11-11 21:47:02.270: ERROR/AndroidRuntime(797): Uncaught handler: thread AsyncTask #1 exiting due to uncaught exception 11-11 21:47:02.280: ERROR/AndroidRuntime(797): java.lang.RuntimeException: An error occured while executing doInBackground() 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at android.os.AsyncTask$3.done(AsyncTask.java:200) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at java.util.concurrent.FutureTask$Sync.innerSetException(FutureTask.java: 234) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:258) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at java.util.concurrent.FutureTask.run(FutureTask.java:122) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at java.util.concurrent.ThreadPoolExecutor$Worker.runTask (ThreadPoolExecutor.java:648) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:673) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at java.lang.Thread.run(Thread.java:1060) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at android.os.Handler.init(Handler.java:121) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at android.widget.Toast.init(Toast.java:68) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at android.widget.Toast.makeText(Toast.java:231) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at foo.bar.MainActivity.onTaskError(MainActivity.java:113) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at foo.bar.MainActivity.access$2(MainActivity.java:110) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at foo.bar.MainActivity$GenerateMangaTitles.doInBackground (MainActivity.java:223) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at foo.bar.MainActivity$GenerateMangaTitles.doInBackground (MainActivity.java:1) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at android.os.AsyncTask$2.call(AsyncTask.java:185) 11-11 21:47:02.280: ERROR/AndroidRuntime(797): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:256) On 11 Nov, 21:24, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: So I've been sifting through example after example of android code, and I see most web requests don't actually catch that many exceptions, maybe because their path is hard coded so there is no room for user error? I'm still confused as the best way to exit my background task gracefully if my get() method raises an exception, at the moment getting anything but a force close just isn't happening Without a stack trace, it will be difficult for anyone to give you advice on this issue. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.2 Available! -- 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] Re: Async thread aborted after catching (all?) exceptions
Ahh yeah that makes total sense now. Can't believe I didn't notice that Thanks again On Nov 11, 10:16 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: Yeah, my bad.. snip 11-11 21:47:02.280: ERROR/AndroidRuntime(797): Caused by: java.lang.RuntimeException: Can't create handler inside thread that has not called Looper.prepare() General rule: always look for the Caused by: entry in the stack trace. Your problem isn't the exception, but what you are doing in the exception handler. Whatever mActivity.onTaskError(e.getMessage()); may be trying to modify the UI, and that's a no-no from a background thread. Whatever you're doing, it's not strictly kosher. What I have done is held onto the Exception object in the AsyncTask instance, then used it in onPostExecute(), when it is safe to update the UI. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 Available! -- 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] Re: AsyncTask and ProgressDialog
I've tried that, too. But again to no avail, nothing I do seems to work. I've tried using the callback features whilst also implementing weak references which also doesn't work. Once I change orientation, the progressDialog never disappears, it's bugging me to hell On 8 Nov, 17:41, Streets Of Boston flyingdutc...@gmail.com wrote: If you do showDialog(dialogId) and dismissDialog(dailogId), Android actively manages the showing and hiding of the dialog on configuration changes. E.g. if you called showDialog(id) and your rotate your screen, Android will make sure that the dialog is shown again when the activity is recreated for the new configuration. To dismiss it, you have to explicitly call dismissDialog(id). However, you must call 'dismissDialog' on the currently active activity. That's where the trick with 'ACTIVE_INSTANCE' comes in: ACTIVE_INSTANCE.showDialog(ACTIVE_TASKING) and ACTIVE_INSTANCE.dismissDialog(DIALOG_TASKING). On Nov 8, 4:28 am,LeeJarvisljjar...@googlemail.com wrote: Well, that's the thing. It's not a progress 'bar' that I can just show/ hide which would seem a lot easier. I'm just using a ProgressDialog that I dismiss in onPostExecute, The code you see above inside of my AsyncTask is what I'm using to show/hide the dialog. I use showDialog () in onPreExecute and dismissDialog() in onPostExecute, I realize one a new activity is created and the old one is killed it'll lose reference to that dialog so I'm guessing that's why dismissDialog() doesn't work (on in fact the code in onPostExecute() doesn't get executed because the phone has change orientation and it's trying to dismiss a dialog which doesn't exist. On 8 Nov, 03:52, Streets Of Boston flyingdutc...@gmail.com wrote: Show us your code that deals with showing/hiding the progress bar and show exactly what doesn't work. Maybe we can figure it out :) On Nov 7, 5:32 pm,LeeJarvisljjar...@googlemail.com wrote: Any other suggestions? I keep trying different things out but nothing seems to work, I keep seeing common applications with the same functionality which is making it more frustrating because I know it should work fine On 7 Nov, 17:29,LeeJarvisljjar...@googlemail.com wrote: Thanks for your reply, it's made me understand things a little better. Unfortunately that still doesn't seem to work.. The Toast popup appears twice, then the ProgressDialog just continues to run regardless On Nov 7, 5:14 pm, Streets Of Boston flyingdutc...@gmail.com wrote: Lance is absolutely right. I ran into this problem a few months ago. Possible solution: Hold a static handle to your currently active instance of your activity (works only if you have at most one active instance of your activity at any given time in your process). public class MyActivity extends Activity { public static final MyActivity ACTIVE_INSTANCE; private final static int DIALOG_TASKING = 1; ProgressDialog mLoadingDialog; @Override public void onCreate(Bundle savedInstanceState) { ACTIVE_INSTANCE = this; super.onCreate(savedInstanceState); setContentView(R.layout.main); new Task().execute(); } @Override public void onDestroy() { super.onDestroy(); ACTIVE_INSTANCE = null; } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_TASKING: mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(Loading stuff..); mLoadingDialog.setCancelable(true); return mLoadingDialog; } return super.onCreateDialog(id); } private static class Task extends AsyncTaskVoid, Void, Void { protected void onPreExecute() { ACTIVE_INSTANCE.showDialog(DIALOG_TASKING); } protected Void doInBackground(Void... unused) { for (int i = 0; i 400; i++) { }; // just to take some time up return null; } protected void onPostExecute(Void unused) { ACTIVE_INSTANCE.dismissDialog (DIALOG_TASKING); Toast.makeText(ACTIVE_INSTANCE, Finished.., Toast.LENGTH_LONG).show(); } } } You may need to put null checks in your code before using ACTIVE_INSTANCE. But, you get the idea :) On Nov 7, 11:45 am,LeeJarvisljjar...@googlemail.com wrote: Ah ok, that makes sense. Thanks for your reply. I understand what you're saying, but in all honesty after trying
[android-developers] Re: AsyncTask and ProgressDialog
Well, that's the thing. It's not a progress 'bar' that I can just show/ hide which would seem a lot easier. I'm just using a ProgressDialog that I dismiss in onPostExecute, The code you see above inside of my AsyncTask is what I'm using to show/hide the dialog. I use showDialog () in onPreExecute and dismissDialog() in onPostExecute, I realize one a new activity is created and the old one is killed it'll lose reference to that dialog so I'm guessing that's why dismissDialog() doesn't work (on in fact the code in onPostExecute() doesn't get executed because the phone has change orientation and it's trying to dismiss a dialog which doesn't exist. On 8 Nov, 03:52, Streets Of Boston flyingdutc...@gmail.com wrote: Show us your code that deals with showing/hiding the progress bar and show exactly what doesn't work. Maybe we can figure it out :) On Nov 7, 5:32 pm, Lee Jarvis ljjar...@googlemail.com wrote: Any other suggestions? I keep trying different things out but nothing seems to work, I keep seeing common applications with the same functionality which is making it more frustrating because I know it should work fine On 7 Nov, 17:29, Lee Jarvis ljjar...@googlemail.com wrote: Thanks for your reply, it's made me understand things a little better. Unfortunately that still doesn't seem to work.. The Toast popup appears twice, then the ProgressDialog just continues to run regardless On Nov 7, 5:14 pm, Streets Of Boston flyingdutc...@gmail.com wrote: Lance is absolutely right. I ran into this problem a few months ago. Possible solution: Hold a static handle to your currently active instance of your activity (works only if you have at most one active instance of your activity at any given time in your process). public class MyActivity extends Activity { public static final MyActivity ACTIVE_INSTANCE; private final static int DIALOG_TASKING = 1; ProgressDialog mLoadingDialog; @Override public void onCreate(Bundle savedInstanceState) { ACTIVE_INSTANCE = this; super.onCreate(savedInstanceState); setContentView(R.layout.main); new Task().execute(); } @Override public void onDestroy() { super.onDestroy(); ACTIVE_INSTANCE = null; } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_TASKING: mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(Loading stuff..); mLoadingDialog.setCancelable(true); return mLoadingDialog; } return super.onCreateDialog(id); } private static class Task extends AsyncTaskVoid, Void, Void { protected void onPreExecute() { ACTIVE_INSTANCE.showDialog(DIALOG_TASKING); } protected Void doInBackground(Void... unused) { for (int i = 0; i 400; i++) { }; // just to take some time up return null; } protected void onPostExecute(Void unused) { ACTIVE_INSTANCE.dismissDialog (DIALOG_TASKING); Toast.makeText(ACTIVE_INSTANCE, Finished.., Toast.LENGTH_LONG).show(); } } } You may need to put null checks in your code before using ACTIVE_INSTANCE. But, you get the idea :) On Nov 7, 11:45 am, Lee Jarvis ljjar...@googlemail.com wrote: Ah ok, that makes sense. Thanks for your reply. I understand what you're saying, but in all honesty after trying another 3 examples I'm still unable to resolve this, could you possibly provide some kind of example for what would work? Seems if I use a reference to a ProgressDialog in my activity it'll leak, and if I use the showDialog() methods it'll continue forever. Thanks On Nov 7, 4:39 pm, Lance Nanek lna...@gmail.com wrote: private final class Task extends AsyncTaskVoid, Void, Void { ... dismissDialog(DIALOG_TASKING); A non-static inner class like this has a reference to the instance of the class that created it. So that dismissDialog call probably goes to the previous instance of your activity in this case. Not the current one if there has been an orientation change and the activity has been recreated. public void onDestroy() { dismissDialog(DIALOG_TASKING); This is called too late to matter. Dialogs created by showDialog are managed by the Activity class. It records which dialogs have to be reshown when the activity is recreated due to an orientation change. It does so right after the call to onSaveInstanceState. That happens
[android-developers] AsyncTask and ProgressDialog
Hey guys, I have the following code.. public class MyActivity extends Activity { private final static int DIALOG_TASKING = 1; ProgressDialog mLoadingDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); new Task().execute(); } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_TASKING: mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(Loading stuff..); mLoadingDialog.setCancelable(true); return mLoadingDialog; } return super.onCreateDialog(id); } private class Task extends AsyncTaskVoid, Void, Void { protected void onPreExecute() { showDialog(DIALOG_TASKING); } protected Void doInBackground(Void... unused) { for (int i = 0; i 400; i++) { }; // just to take some time up return null; } protected void onPostExecute(Void unused) { dismissDialog(DIALOG_TASKING); Toast.makeText(MyActivity.this, Finished.., Toast.LENGTH_LONG).show(); } } } The code works fine, except when I try and change screen orientation, the progress dialog doesn't disappear and the task seems to be executed again, I realize this is because the onCreate() method is being called again on orientation change perhaps? What would be the best solution for this issue? Thanks for any response. -- 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] Re: AsyncTask and ProgressDialog
Ok great, thanks. I've adapted my code and added a static flag to my activity, just for testing purposes.. This is my code now.. package net.gullycorp.gully; import android.app.Activity; import android.app.Dialog; import android.app.ProgressDialog; import android.os.AsyncTask; import android.os.Bundle; import android.widget.Toast; public class GullyActivity extends Activity { private final static int DIALOG_TASKING = 1; private static boolean mTaskComplete = false; ProgressDialog mLoadingDialog; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); if (!mTaskComplete) { new Task().execute(); // fetch our stuff } } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_TASKING: mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(Loading stuff..); mLoadingDialog.setCancelable(true); return mLoadingDialog; } return super.onCreateDialog(id); } private final class Task extends AsyncTaskVoid, Void, Void { protected void onPreExecute() { showDialog(DIALOG_TASKING); } protected Void doInBackground(Void... unused) { for (int i = 0; i 400; i++) { }; // just to take some time up mTaskComplete = true; return null; } protected void onPostExecute(Void unused) { dismissDialog(DIALOG_TASKING); Toast.makeText(GullyActivity.this, Finished.., Toast.LENGTH_SHORT).show(); } } } This code (kinda) works, the only problem is dismissing the dialog if the activity is recreated. I've tried dismissing it if mTaskComplete is true but I guess by that time it's lost reference to the ProgressDialog. Thanks On Nov 7, 2:14 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: The code works fine, except when I try and change screen orientation, the progress dialog doesn't disappear and the task seems to be executed again, I realize this is because the onCreate() method is being called again on orientation change perhaps? Yes. By default, on an orientation change, activities are destroyed and recreated. What would be the best solution for this issue? I don't know about best. Some options include: 1. A static flag or something that indicates whether your background task is running, so you only fire off the task in onCreate() if that flag is false. 2. Overriding the default orientation-handling code, so your activity is not destroyed and recreated: http://www.androidguys.com/2008/11/11/rotational-forces-part-three/ 3. Finding some other way of handling your background work that does not require it to be invoked every time the activity starts up, if that's possible. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 In Print! -- 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] Re: AsyncTask and ProgressDialog
I apologise if I'm missing something or just being stupid.. But i've tried the following.. @Override public void onDestroy() { dismissDialog(DIALOG_TASKING); super.onDestroy(); } The dialog is only dismissed if I DONT change orientation, otherwise the finished toast will show, but the ProgressDialog will never actually disappear. On Nov 7, 2:41 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: This code (kinda) works, the only problem is dismissing the dialog if the activity is recreated. I've tried dismissing it if mTaskComplete is true but I guess by that time it's lost reference to the ProgressDialog. You may need to dismiss the dialog in onDestroy() and reopen it in onCreate(), if the flag is true. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books -- 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] Re: AsyncTask and ProgressDialog
Anyone other feedback on this? I'm confused as to why this isn't simpler.. All I want to do is display the ProgressDialog until the task is complete, then get rid of it.. Anyone would think this was trivial. No matter what I do I'm unable to remove the dialog once the screens orientation has altered. Thanks for any replys On 7 Nov, 14:53, Lee Jarvis ljjar...@googlemail.com wrote: I apologise if I'm missing something or just being stupid.. But i've tried the following.. @Override public void onDestroy() { dismissDialog(DIALOG_TASKING); super.onDestroy(); } The dialog is only dismissed if I DONT change orientation, otherwise the finished toast will show, but the ProgressDialog will never actually disappear. On Nov 7, 2:41 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: This code (kinda) works, the only problem is dismissing the dialog if the activity is recreated. I've tried dismissing it if mTaskComplete is true but I guess by that time it's lost reference to the ProgressDialog. You may need to dismiss the dialog in onDestroy() and reopen it in onCreate(), if the flag is true. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books -- 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] Re: AsyncTask and ProgressDialog
Ah ok, that makes sense. Thanks for your reply. I understand what you're saying, but in all honesty after trying another 3 examples I'm still unable to resolve this, could you possibly provide some kind of example for what would work? Seems if I use a reference to a ProgressDialog in my activity it'll leak, and if I use the showDialog() methods it'll continue forever. Thanks On Nov 7, 4:39 pm, Lance Nanek lna...@gmail.com wrote: private final class Task extends AsyncTaskVoid, Void, Void { ... dismissDialog(DIALOG_TASKING); A non-static inner class like this has a reference to the instance of the class that created it. So that dismissDialog call probably goes to the previous instance of your activity in this case. Not the current one if there has been an orientation change and the activity has been recreated. public void onDestroy() { dismissDialog(DIALOG_TASKING); This is called too late to matter. Dialogs created by showDialog are managed by the Activity class. It records which dialogs have to be reshown when the activity is recreated due to an orientation change. It does so right after the call to onSaveInstanceState. That happens before onDestroy. On Nov 7, 9:53 am, Lee Jarvis ljjar...@googlemail.com wrote: I apologise if I'm missing something or just being stupid.. But i've tried the following.. @Override public void onDestroy() { dismissDialog(DIALOG_TASKING); super.onDestroy(); } The dialog is only dismissed if I DONT change orientation, otherwise the finished toast will show, but the ProgressDialog will never actually disappear. On Nov 7, 2:41 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: This code (kinda) works, the only problem is dismissing the dialog if the activity is recreated. I've tried dismissing it if mTaskComplete is true but I guess by that time it's lost reference to the ProgressDialog. You may need to dismiss the dialog in onDestroy() and reopen it in onCreate(), if the flag is true. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books -- 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] Re: AsyncTask and ProgressDialog
Thanks for your reply, it's made me understand things a little better. Unfortunately that still doesn't seem to work.. The Toast popup appears twice, then the ProgressDialog just continues to run regardless On Nov 7, 5:14 pm, Streets Of Boston flyingdutc...@gmail.com wrote: Lance is absolutely right. I ran into this problem a few months ago. Possible solution: Hold a static handle to your currently active instance of your activity (works only if you have at most one active instance of your activity at any given time in your process). public class MyActivity extends Activity { public static final MyActivity ACTIVE_INSTANCE; private final static int DIALOG_TASKING = 1; ProgressDialog mLoadingDialog; @Override public void onCreate(Bundle savedInstanceState) { ACTIVE_INSTANCE = this; super.onCreate(savedInstanceState); setContentView(R.layout.main); new Task().execute(); } @Override public void onDestroy() { super.onDestroy(); ACTIVE_INSTANCE = null; } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_TASKING: mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(Loading stuff..); mLoadingDialog.setCancelable(true); return mLoadingDialog; } return super.onCreateDialog(id); } private static class Task extends AsyncTaskVoid, Void, Void { protected void onPreExecute() { ACTIVE_INSTANCE.showDialog(DIALOG_TASKING); } protected Void doInBackground(Void... unused) { for (int i = 0; i 400; i++) { }; // just to take some time up return null; } protected void onPostExecute(Void unused) { ACTIVE_INSTANCE.dismissDialog (DIALOG_TASKING); Toast.makeText(ACTIVE_INSTANCE, Finished.., Toast.LENGTH_LONG).show(); } } } You may need to put null checks in your code before using ACTIVE_INSTANCE. But, you get the idea :) On Nov 7, 11:45 am, Lee Jarvis ljjar...@googlemail.com wrote: Ah ok, that makes sense. Thanks for your reply. I understand what you're saying, but in all honesty after trying another 3 examples I'm still unable to resolve this, could you possibly provide some kind of example for what would work? Seems if I use a reference to a ProgressDialog in my activity it'll leak, and if I use the showDialog() methods it'll continue forever. Thanks On Nov 7, 4:39 pm, Lance Nanek lna...@gmail.com wrote: private final class Task extends AsyncTaskVoid, Void, Void { ... dismissDialog(DIALOG_TASKING); A non-static inner class like this has a reference to the instance of the class that created it. So that dismissDialog call probably goes to the previous instance of your activity in this case. Not the current one if there has been an orientation change and the activity has been recreated. public void onDestroy() { dismissDialog(DIALOG_TASKING); This is called too late to matter. Dialogs created by showDialog are managed by the Activity class. It records which dialogs have to be reshown when the activity is recreated due to an orientation change. It does so right after the call to onSaveInstanceState. That happens before onDestroy. On Nov 7, 9:53 am, Lee Jarvis ljjar...@googlemail.com wrote: I apologise if I'm missing something or just being stupid.. But i've tried the following.. @Override public void onDestroy() { dismissDialog(DIALOG_TASKING); super.onDestroy(); } The dialog is only dismissed if I DONT change orientation, otherwise the finished toast will show, but the ProgressDialog will never actually disappear. On Nov 7, 2:41 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: This code (kinda) works, the only problem is dismissing the dialog if the activity is recreated. I've tried dismissing it if mTaskComplete is true but I guess by that time it's lost reference to the ProgressDialog. You may need to dismiss the dialog in onDestroy() and reopen it in onCreate(), if the flag is true. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http://commonsware.com/books-Hide quoted text - - Show quoted text - -- 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
[android-developers] Re: AsyncTask and ProgressDialog
Any other suggestions? I keep trying different things out but nothing seems to work, I keep seeing common applications with the same functionality which is making it more frustrating because I know it should work fine On 7 Nov, 17:29, Lee Jarvis ljjar...@googlemail.com wrote: Thanks for your reply, it's made me understand things a little better. Unfortunately that still doesn't seem to work.. The Toast popup appears twice, then the ProgressDialog just continues to run regardless On Nov 7, 5:14 pm, Streets Of Boston flyingdutc...@gmail.com wrote: Lance is absolutely right. I ran into this problem a few months ago. Possible solution: Hold a static handle to your currently active instance of your activity (works only if you have at most one active instance of your activity at any given time in your process). public class MyActivity extends Activity { public static final MyActivity ACTIVE_INSTANCE; private final static int DIALOG_TASKING = 1; ProgressDialog mLoadingDialog; @Override public void onCreate(Bundle savedInstanceState) { ACTIVE_INSTANCE = this; super.onCreate(savedInstanceState); setContentView(R.layout.main); new Task().execute(); } @Override public void onDestroy() { super.onDestroy(); ACTIVE_INSTANCE = null; } @Override protected Dialog onCreateDialog(int id) { switch (id) { case DIALOG_TASKING: mLoadingDialog = new ProgressDialog(this); mLoadingDialog.setMessage(Loading stuff..); mLoadingDialog.setCancelable(true); return mLoadingDialog; } return super.onCreateDialog(id); } private static class Task extends AsyncTaskVoid, Void, Void { protected void onPreExecute() { ACTIVE_INSTANCE.showDialog(DIALOG_TASKING); } protected Void doInBackground(Void... unused) { for (int i = 0; i 400; i++) { }; // just to take some time up return null; } protected void onPostExecute(Void unused) { ACTIVE_INSTANCE.dismissDialog (DIALOG_TASKING); Toast.makeText(ACTIVE_INSTANCE, Finished.., Toast.LENGTH_LONG).show(); } } } You may need to put null checks in your code before using ACTIVE_INSTANCE. But, you get the idea :) On Nov 7, 11:45 am, Lee Jarvis ljjar...@googlemail.com wrote: Ah ok, that makes sense. Thanks for your reply. I understand what you're saying, but in all honesty after trying another 3 examples I'm still unable to resolve this, could you possibly provide some kind of example for what would work? Seems if I use a reference to a ProgressDialog in my activity it'll leak, and if I use the showDialog() methods it'll continue forever. Thanks On Nov 7, 4:39 pm, Lance Nanek lna...@gmail.com wrote: private final class Task extends AsyncTaskVoid, Void, Void { ... dismissDialog(DIALOG_TASKING); A non-static inner class like this has a reference to the instance of the class that created it. So that dismissDialog call probably goes to the previous instance of your activity in this case. Not the current one if there has been an orientation change and the activity has been recreated. public void onDestroy() { dismissDialog(DIALOG_TASKING); This is called too late to matter. Dialogs created by showDialog are managed by the Activity class. It records which dialogs have to be reshown when the activity is recreated due to an orientation change. It does so right after the call to onSaveInstanceState. That happens before onDestroy. On Nov 7, 9:53 am, Lee Jarvis ljjar...@googlemail.com wrote: I apologise if I'm missing something or just being stupid.. But i've tried the following.. @Override public void onDestroy() { dismissDialog(DIALOG_TASKING); super.onDestroy(); } The dialog is only dismissed if I DONT change orientation, otherwise the finished toast will show, but the ProgressDialog will never actually disappear. On Nov 7, 2:41 pm, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: This code (kinda) works, the only problem is dismissing the dialog if the activity is recreated. I've tried dismissing it if mTaskComplete is true but I guess by that time it's lost reference to the ProgressDialog. You may need to dismiss the dialog in onDestroy() and reopen it in onCreate(), if the flag is true. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy Android App Developer Books:http
[android-developers] ListActivity implements OnItemLongClickListener
I'm attempting to implement a long click listener on a list activity that simply works the same way as when you long click on a contact in your address book. That is, displaying an AlertDialog with a list of options (one option might be to add the value clicked as a favorite or something). I've attempted to use something like the following.. http://pastie.org/655392 I realize this is wrong and my implementation is totally screwed up, but I'm getting really confused with how to implement this. Any help would be great. Thanks Regards, Lee --~--~-~--~~~---~--~~ 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] Re: ListActivity implements OnItemLongClickListener
That works great, thankyou. One more thing, though. I have tried to mess around with onContextItemSelected() and attempted to get the original text from the list item I clicked through the ContextMenuInfo interface, but there doesn't seem to be a clear way to achieve this. All I basically need to (lets say, set a favorite) is the title or string of the list item I clicked to bring up the context menu. Thanks. On Oct 15, 1:00 am, Jason Proctor jason.android.li...@gmail.com wrote: the dialog that comes up when you long-click on a contact is actually a contextual menu. i've done this in my app for much the same reason and it's straightforward. call activity.registerForContextMenu(view), then implement View.OnCreateContextualMenuListener in your activity. when the user long taps on view, onCreateContextMenu() gets called off your activity. you get passed a Menu reference, which you build according to your context. this gets shown, the user picks one, and so forth. hth I'm attempting to implement a long click listener on a list activity that simply works the same way as when you long click on a contact in your address book. That is, displaying an AlertDialog with a list of options (one option might be to add the value clicked as a favorite or something). I've attempted to use something like the following.. http://pastie.org/655392I realize this is wrong and my implementation is totally screwed up, but I'm getting really confused with how to implement this. Any help would be great. Thanks Regards, Lee -- jason.vp.engineering.particle --~--~-~--~~~---~--~~ 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] Re: ListActivity implements OnItemLongClickListener
Ok thanks, well I ended up using the following.. AdapterView.AdapterContextMenuInfo info; info = (AdapterView.AdapterContextMenuInfo) menuInfo; ListView lv = getListView(); String title = lv.getItemAtPosition(info.position).toString(); I realize there are other ways of achieving this, what would the best be? I don't seem to be able to grab the text as easily using any other methods. Thanks. On Oct 15, 1:48 am, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: That works great, thankyou. One more thing, though. I have tried to mess around with onContextItemSelected() and attempted to get the original text from the list item I clicked through the ContextMenuInfo interface, but there doesn't seem to be a clear way to achieve this. All I basically need to (lets say, set a favorite) is the title or string of the list item I clicked to bring up the context menu. Inside an onContextItemSelected(MenuItem item) method, you can do: AdapterView.AdapterContextMenuInfo info= (AdapterView.AdapterContextMenuInfo)item.getMenuInfo(); That will give you the ID, position, and View of the row in the ListView that was long-tapped to bring up the context menu. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _The Busy Coder's Guide to *Advanced* Android Development_ Version 1.1 Available! --~--~-~--~~~---~--~~ 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] ListActivity and an alternative view for error message?
So I have a ListActivity that implements an ArrayAdapter list. I have a control statement within onCreate() that checks if we have any Array values to populate our list, if we do.. set up the list and display it. The problem is, what happens when we don't. Ideally what I'd like to do is simply display an alert dialog telling the user no values exist and then return to the previous activity, what's the best way to do this? I've tried the following... http://pastie.org/653790 But the dialog doesn't appear, which isn't really any surprise. What would be the best approach for this? Regards, Lee --~--~-~--~~~---~--~~ 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] Re: ListActivity and an alternative view for error message?
Ahh how silly of me. Thankyou. Regards, Lee On 14 Oct, 01:46, Dianne Hackborn hack...@android.com wrote: You need to call .show() on the dialog to have it shown. There should be no problem with showing a dialog in onCreate(). (There was a problem with this in 1.0, but that was ages ago.) On Tue, Oct 13, 2009 at 5:42 PM, Lee Jarvis ljjar...@googlemail.com wrote: So I have a ListActivity that implements an ArrayAdapter list. I have a control statement within onCreate() that checks if we have any Array values to populate our list, if we do.. set up the list and display it. The problem is, what happens when we don't. Ideally what I'd like to do is simply display an alert dialog telling the user no values exist and then return to the previous activity, what's the best way to do this? I've tried the following... http://pastie.org/653790 But the dialog doesn't appear, which isn't really any surprise. What would be the best approach for this? Regards, Lee -- Dianne Hackborn Android framework engineer hack...@android.com Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails. All such questions should be posted on public forums, where I and others can see and answer them. --~--~-~--~~~---~--~~ 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] Re: HTTP GET and ProgressDialog
Ok so I kind of implemented this, but it forces close when I click the button.. What am I doing wrong? package net.gullycorp.example.webtest; import java.io.IOException; import org.apache.http.client.ClientProtocolException; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class WebTest extends Activity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button clickme = (Button) findViewById(R.id.clickme); clickme.setOnClickListener(this); } public void onClick(View view) { int id = view.getId(); switch(id) { case R.id.clickme: EditText urlText = (EditText) findViewById(R.id.textbox); String url = urlText.getText().toString(); grabSource(url); break; } } private void grabSource(String url) { new GrabURLTask().execute(); } private class GrabURLTask extends AsyncTaskString, Void, Void { protected void onPreExecute() { Utilities.showToast(WebTest.this, Loading.., true); } protected Void doInBackground(String... params) { final Webat client = new Webat(); boolean success = false; try { client.getURL(params[0]); success = true; } catch (ClientProtocolException e) { Utilities.showToast(WebTest.this, e.getMessage(), true); cancel(true); } catch (IOException e) { Utilities.showToast(WebTest.this, e.getMessage(), true); cancel(true); } return null; } protected void onPostExecute(Void unused) { Utilities.showToast(WebTest.this, Source loaded., true); } } } === Apologies for the large paste, I can pastie it if it's preferable? Thanks, Lee On Oct 11, 11:24 pm, Mark Murphy mmur...@commonsware.com wrote: LeeJarviswrote: Oh, I don't plan on using half of the dialogs and such I'm using in that test application. I too prefer to write things in an activity over a dialog. I just want to get this to work. Unfortunately I'm getting confused as hell. I can see how this should be implemented, but I can't get it to do so. I guess I'll try and find some examples of using AsyncTask that aren't too complex. Yeah, AsyncTask went a bit overboard with the varargs and such, IMHO. My EndlessAdapter component has about as trivial of an AsyncTask implementation as you'll find: http://github.com/commonsguy/cwac-endless -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 Available! --~--~-~--~~~---~--~~ 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] Re: HTTP GET and ProgressDialog
Sorry, I realized in that above example I passed to arguments to execute(), not that it makes any difference to my issue. On Oct 12, 11:58 pm, Lee Jarvis ljjar...@googlemail.com wrote: Ok so I kind of implemented this, but it forces close when I click the button.. What am I doing wrong? package net.gullycorp.example.webtest; import java.io.IOException; import org.apache.http.client.ClientProtocolException; import android.app.Activity; import android.app.AlertDialog; import android.content.DialogInterface; import android.os.AsyncTask; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; public class WebTest extends Activity implements OnClickListener { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Button clickme = (Button) findViewById(R.id.clickme); clickme.setOnClickListener(this); } public void onClick(View view) { int id = view.getId(); switch(id) { case R.id.clickme: EditText urlText = (EditText) findViewById(R.id.textbox); String url = urlText.getText().toString(); grabSource(url); break; } } private void grabSource(String url) { new GrabURLTask().execute(); } private class GrabURLTask extends AsyncTaskString, Void, Void { protected void onPreExecute() { Utilities.showToast(WebTest.this, Loading.., true); } protected Void doInBackground(String... params) { final Webat client = new Webat(); boolean success = false; try { client.getURL(params[0]); success = true; } catch (ClientProtocolException e) { Utilities.showToast(WebTest.this, e.getMessage(), true); cancel(true); } catch (IOException e) { Utilities.showToast(WebTest.this, e.getMessage(), true); cancel(true); } return null; } protected void onPostExecute(Void unused) { Utilities.showToast(WebTest.this, Source loaded., true); } } } === Apologies for the large paste, I can pastie it if it's preferable? Thanks, Lee On Oct 11, 11:24 pm, Mark Murphy mmur...@commonsware.com wrote: LeeJarviswrote: Oh, I don't plan on using half of the dialogs and such I'm using in that test application. I too prefer to write things in an activity over a dialog. I just want to get this to work. Unfortunately I'm getting confused as hell. I can see how this should be implemented, but I can't get it to do so. I guess I'll try and find some examples of using AsyncTask that aren't too complex. Yeah, AsyncTask went a bit overboard with the varargs and such, IMHO. My EndlessAdapter component has about as trivial of an AsyncTask implementation as you'll find: http://github.com/commonsguy/cwac-endless -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 Available! --~--~-~--~~~---~--~~ 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] Re: HTTP GET and ProgressDialog
Ok so I updated the code again, and I guess it pretty much works. Would any of this be discouraged? Or would there be a better way of doing this? http://pastie.org/652258 Regards, Lee --~--~-~--~~~---~--~~ 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] Internet Permission issue and HTTP Requests
Hi, I am trying to develop an application that simply downloads a web page, creates a new TextView, and sets the text to the web page's source (or content). I have been playing with apaches HTTP library and have some example code up and running, everything 'should' work, but it doesn't. Every time I try to run the application I get the following error message from the emulator: [2009-10-10 11:34:03 - WebGrab]ActivityManager: Starting: Intent etc [2009-10-10 11:34:03 - WebGrab]ActivityManager: [1] Killed am start -n net I have the internet permission enabled in my manifest. Here is my example code.. http://pastie.org/649368 Thanks for any replies. Regards, Lee --~--~-~--~~~---~--~~ 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] HTTP GET and ProgressDialog
Hi guys, I have a small test application that simply grabs a URL from an EditText box, before downloading the page source for the URL, prompting the user to ask if it should display the contents, then doing so, or returning state. I would like to incorporate a ProgressDialog to appear whilst the GET request is in action. I understand this would require threads, and I have attempted to implement this, but to no avail. Could anyone assist in this matter? My code is here: http://pastie.org/650756 Thanks for any reply Regards, Lee --~--~-~--~~~---~--~~ 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] Re: HTTP GET and ProgressDialog
Thanks, I'll give it a go. What's with the (ick)? AlertDialog? On 11 Oct, 22:08, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: Hi guys, I have a small test application that simply grabs a URL from an EditText box, before downloading the page source for the URL, prompting the user to ask if it should display the contents, then doing so, or returning state. I would like to incorporate a ProgressDialog to appear whilst the GET request is in action. I understand this would require threads, and I have attempted to implement this, but to no avail. Could anyone assist in this matter? Use AsyncTask. Open the ProgressDialog in onPreExecute() or before you start the AsyncTask. Do the HTTP request in doInBackground(). Remove the ProgressDialog and (ick) display your AlertDialog from onPostExecute(). -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 Available! --~--~-~--~~~---~--~~ 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] Re: HTTP GET and ProgressDialog
Oh, I don't plan on using half of the dialogs and such I'm using in that test application. I too prefer to write things in an activity over a dialog. I just want to get this to work. Unfortunately I'm getting confused as hell. I can see how this should be implemented, but I can't get it to do so. I guess I'll try and find some examples of using AsyncTask that aren't too complex. On 11 Oct, 22:53, Mark Murphy mmur...@commonsware.com wrote: Lee Jarvis wrote: What's with the (ick)? AlertDialog? Well, in your test app, it's probably fine. I worry about people overusing modal dialogs, doing things in a dialog that ought to be in an activity. -- Mark Murphy (a Commons Guy)http://commonsware.com|http://twitter.com/commonsguy _Android Programming Tutorials_ Version 1.0 Available! --~--~-~--~~~---~--~~ 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 -~--~~~~--~~--~--~---