Re: [android-developers] Re: Async Task, rotation and indeterminate progressbar in custom header.
Hi! there joe only today i saw your answers, im going with the maintain reference of the task in the application class route. But i still have some doubts here, i need to replicate the behaviour of dealing with async tasks on rotation but with the switching from activity A to B. I want to refresh the reference of the activity in the async task class. So if A launched the async task and i go to B i want the ASync Task to reference B after the transisiton, but i still want to deal with the rotation. Im also having a reference of the progressbar in the application context but if i save the task there, i wont need the progressbar one i think, what do you think? regards, On Mon, Sep 26, 2011 at 10:19 PM, joebowbeer joe.bowb...@gmail.com wrote: My apologies: I thought I was responding to a different thread, concerning the rotating async task problem. Responding to you question: Yes. Maintaining the state (and async task itself) in the application object is a reasonable way to handle this. If you need persistence across application/process instances, you'll need to persist progress in shared preferences or another persistent store. On Sep 26, 2:14 pm, joebowbeer joe.bowb...@gmail.com wrote: I've also solved this problem in the way you've described: by managing the task instance in the application object. This does burden your application implementation with task details that logically are the responsibility of an activity or fragment. In the interest of robustness, though, I do like to keep a tight grip on thread instances and centralized management via the application object accomplishes that. The other approaches described in this thread are: 1. Stop/cancel the task on rotation but remember what it was doing and restart it when the activity is restarted. 2. Don't stop the task on rotation but detach from it, retain its instance (onRetainNonConfigurationInstance), and reattach to it when the new activity is created. (A generalized version of Mark's async task can be helpful here.) Joe On Sep 23, 6:29 pm, João Rossa joao.ro...@gmail.com wrote: The use case is that the user should always see the loading progressbar if there's any background work being done in whatever activity the user is and if the task was launched from another activity. I tried putting a reference in the application class to the progressbar and then refresh it in the activities in the oncreate and onrestart,that the way the task will always have the refreshed reference on the postexecute method Any inconvinients on this procedure? regards, On Fri, Sep 23, 2011 at 7:13 PM, blake blake.me...@gmail.com wrote: AsyncTasks are a nifty tool but they have a fairly limited specific set of uses. The previous responses have pointed out a several problems with this code: you can't keep static refs to Activites or Views, multiple Activities can't share a progress bar, etc. I don't understand the use case, but I agree with Mark that, from the code you've supplied, this might be better done as an IntentService or as a pair of Fragments. I'm going to be giving a Webinar on the pitfalls surrounding AsyncTasks next week, on the 29th: http://oreillynet.com/pub/e/2061 -blake Programming Android, FTW! http://oreilly.com/catalog/0636920010364 -- 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 -- 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 Task, rotation and indeterminate progressbar in custom header.
I've also solved this problem in the way you've described: by managing the task instance in the application object. This does burden your application implementation with task details that logically are the responsibility of an activity or fragment. In the interest of robustness, though, I do like to keep a tight grip on thread instances and centralized management via the application object accomplishes that. The other approaches described in this thread are: 1. Stop/cancel the task on rotation but remember what it was doing and restart it when the activity is restarted. 2. Don't stop the task on rotation but detach from it, retain its instance (onRetainNonConfigurationInstance), and reattach to it when the new activity is created. (A generalized version of Mark's async task can be helpful here.) Joe On Sep 23, 6:29 pm, João Rossa joao.ro...@gmail.com wrote: The use case is that the user should always see the loading progressbar if there's any background work being done in whatever activity the user is and if the task was launched from another activity. I tried putting a reference in the application class to the progressbar and then refresh it in the activities in the oncreate and onrestart,that the way the task will always have the refreshed reference on the postexecute method Any inconvinients on this procedure? regards, On Fri, Sep 23, 2011 at 7:13 PM, blake blake.me...@gmail.com wrote: AsyncTasks are a nifty tool but they have a fairly limited specific set of uses. The previous responses have pointed out a several problems with this code: you can't keep static refs to Activites or Views, multiple Activities can't share a progress bar, etc. I don't understand the use case, but I agree with Mark that, from the code you've supplied, this might be better done as an IntentService or as a pair of Fragments. I'm going to be giving a Webinar on the pitfalls surrounding AsyncTasks next week, on the 29th: http://oreillynet.com/pub/e/2061 -blake Programming Android, FTW! http://oreilly.com/catalog/0636920010364 -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
My apologies: I thought I was responding to a different thread, concerning the rotating async task problem. Responding to you question: Yes. Maintaining the state (and async task itself) in the application object is a reasonable way to handle this. If you need persistence across application/process instances, you'll need to persist progress in shared preferences or another persistent store. On Sep 26, 2:14 pm, joebowbeer joe.bowb...@gmail.com wrote: I've also solved this problem in the way you've described: by managing the task instance in the application object. This does burden your application implementation with task details that logically are the responsibility of an activity or fragment. In the interest of robustness, though, I do like to keep a tight grip on thread instances and centralized management via the application object accomplishes that. The other approaches described in this thread are: 1. Stop/cancel the task on rotation but remember what it was doing and restart it when the activity is restarted. 2. Don't stop the task on rotation but detach from it, retain its instance (onRetainNonConfigurationInstance), and reattach to it when the new activity is created. (A generalized version of Mark's async task can be helpful here.) Joe On Sep 23, 6:29 pm, João Rossa joao.ro...@gmail.com wrote: The use case is that the user should always see the loading progressbar if there's any background work being done in whatever activity the user is and if the task was launched from another activity. I tried putting a reference in the application class to the progressbar and then refresh it in the activities in the oncreate and onrestart,that the way the task will always have the refreshed reference on the postexecute method Any inconvinients on this procedure? regards, On Fri, Sep 23, 2011 at 7:13 PM, blake blake.me...@gmail.com wrote: AsyncTasks are a nifty tool but they have a fairly limited specific set of uses. The previous responses have pointed out a several problems with this code: you can't keep static refs to Activites or Views, multiple Activities can't share a progress bar, etc. I don't understand the use case, but I agree with Mark that, from the code you've supplied, this might be better done as an IntentService or as a pair of Fragments. I'm going to be giving a Webinar on the pitfalls surrounding AsyncTasks next week, on the 29th: http://oreillynet.com/pub/e/2061 -blake Programming Android, FTW! http://oreilly.com/catalog/0636920010364 -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
IS there a way to avoid the static references to the views, but at the same time giving the possibility of the tasks to change the visibility of the progressbar even if the current activity visible is not the one who laucnhed the task initially? -- 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 Task, rotation and indeterminate progressbar in custom header.
Don't hold static references to Activities or Views. You will run into memory issues and such. But you could put your instance of ProgressBarThread into a static reference that is accessible by Activity B. Then Activity B can register/attach and de-register/detach to this background task as well during its lifecycle. This would allow the ProgressBarThread to update both activities A and B. -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
Ok ProgressBarThread is already a static inner class, so what you're telling is to change the instance reference to static too: private ProgressBarThread task=null; to private static ProgressBarThread task=null; But now how i tell the task initiated by activity A to attach to the current Activity???And how does rotation affects this? regards, On Fri, Sep 23, 2011 at 4:40 PM, Streets Of Boston flyingdutc...@gmail.comwrote: Don't hold static references to Activities or Views. You will run into memory issues and such. But you could put your instance of ProgressBarThread into a static reference that is accessible by Activity B. Then Activity B can register/attach and de-register/detach to this background task as well during its lifecycle. This would allow the ProgressBarThread to update both activities A and B. -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
On Fri, Sep 23, 2011 at 10:25 AM, Bluemercury joao.ro...@gmail.com wrote: IS there a way to avoid the static references to the views, but at the same time giving the possibility of the tasks to change the visibility of the progressbar even if the current activity visible is not the one who laucnhed the task initially? The activities cannot share a progress bar, period. They each have their own progress bar. When you switch between activities, put the progress value (e.g., getProgress()) in an extra, so the new activity can set its progress bar to match. When you handle rotation events, pass the progress value via onSaveInstanceState(), or possibly as part of the state you pass (along with your AsyncTask) in onRetainNonConfigurationInstance(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
Its an indeterminate progressbar the only thing i need is to hide or show the animation, nothing else, but i just to reflect there background work being done from whatever activity started it, even if the current activity was not responsible... regards, On Fri, Sep 23, 2011 at 5:01 PM, Mark Murphy mmur...@commonsware.comwrote: On Fri, Sep 23, 2011 at 10:25 AM, Bluemercury joao.ro...@gmail.com wrote: IS there a way to avoid the static references to the views, but at the same time giving the possibility of the tasks to change the visibility of the progressbar even if the current activity visible is not the one who laucnhed the task initially? The activities cannot share a progress bar, period. They each have their own progress bar. When you switch between activities, put the progress value (e.g., getProgress()) in an extra, so the new activity can set its progress bar to match. When you handle rotation events, pass the progress value via onSaveInstanceState(), or possibly as part of the state you pass (along with your AsyncTask) in onRetainNonConfigurationInstance(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
Sounds like this should not be an AsyncTask, but perhaps an IntentService instead. 2011/9/23 João Rossa joao.ro...@gmail.com: Its an indeterminate progressbar the only thing i need is to hide or show the animation, nothing else, but i just to reflect there background work being done from whatever activity started it, even if the current activity was not responsible... regards, On Fri, Sep 23, 2011 at 5:01 PM, Mark Murphy mmur...@commonsware.com wrote: On Fri, Sep 23, 2011 at 10:25 AM, Bluemercury joao.ro...@gmail.com wrote: IS there a way to avoid the static references to the views, but at the same time giving the possibility of the tasks to change the visibility of the progressbar even if the current activity visible is not the one who laucnhed the task initially? The activities cannot share a progress bar, period. They each have their own progress bar. When you switch between activities, put the progress value (e.g., getProgress()) in an extra, so the new activity can set its progress bar to match. When you handle rotation events, pass the progress value via onSaveInstanceState(), or possibly as part of the state you pass (along with your AsyncTask) in onRetainNonConfigurationInstance(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- 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 -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
** sorry for the bad english... ts an indeterminate progressbar the only thing i need is to hide or show the animation, nothing else, but i just want to reflect that there's background work being done from whatever activity that started it, even if the current activity was not responsible. regards, 2011/9/23 João Rossa joao.ro...@gmail.com Its an indeterminate progressbar the only thing i need is to hide or show the animation, nothing else, but i just to reflect there background work being done from whatever activity started it, even if the current activity was not responsible... regards, On Fri, Sep 23, 2011 at 5:01 PM, Mark Murphy mmur...@commonsware.comwrote: On Fri, Sep 23, 2011 at 10:25 AM, Bluemercury joao.ro...@gmail.com wrote: IS there a way to avoid the static references to the views, but at the same time giving the possibility of the tasks to change the visibility of the progressbar even if the current activity visible is not the one who laucnhed the task initially? The activities cannot share a progress bar, period. They each have their own progress bar. When you switch between activities, put the progress value (e.g., getProgress()) in an extra, so the new activity can set its progress bar to match. When you handle rotation events, pass the progress value via onSaveInstanceState(), or possibly as part of the state you pass (along with your AsyncTask) in onRetainNonConfigurationInstance(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
What if i create a reference of the progressbar on the application class and refresh it on the onCreate methods of the activities? On Fri, Sep 23, 2011 at 5:09 PM, Mark Murphy mmur...@commonsware.comwrote: Sounds like this should not be an AsyncTask, but perhaps an IntentService instead. 2011/9/23 João Rossa joao.ro...@gmail.com: Its an indeterminate progressbar the only thing i need is to hide or show the animation, nothing else, but i just to reflect there background work being done from whatever activity started it, even if the current activity was not responsible... regards, On Fri, Sep 23, 2011 at 5:01 PM, Mark Murphy mmur...@commonsware.com wrote: On Fri, Sep 23, 2011 at 10:25 AM, Bluemercury joao.ro...@gmail.com wrote: IS there a way to avoid the static references to the views, but at the same time giving the possibility of the tasks to change the visibility of the progressbar even if the current activity visible is not the one who laucnhed the task initially? The activities cannot share a progress bar, period. They each have their own progress bar. When you switch between activities, put the progress value (e.g., getProgress()) in an extra, so the new activity can set its progress bar to match. When you handle rotation events, pass the progress value via onSaveInstanceState(), or possibly as part of the state you pass (along with your AsyncTask) in onRetainNonConfigurationInstance(). -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- 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 -- Mark Murphy (a Commons Guy) http://commonsware.com | http://github.com/commonsguy http://commonsware.com/blog | http://twitter.com/commonsguy Warescription: Three Android Books, Plus Updates, One Low Price! -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
AsyncTasks are a nifty tool but they have a fairly limited specific set of uses. The previous responses have pointed out a several problems with this code: you can't keep static refs to Activites or Views, multiple Activities can't share a progress bar, etc. I don't understand the use case, but I agree with Mark that, from the code you've supplied, this might be better done as an IntentService or as a pair of Fragments. I'm going to be giving a Webinar on the pitfalls surrounding AsyncTasks next week, on the 29th: http://oreillynet.com/pub/e/2061 -blake Programming Android, FTW! http://oreilly.com/catalog/0636920010364 -- 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] Re: Async Task, rotation and indeterminate progressbar in custom header.
The use case is that the user should always see the loading progressbar if there's any background work being done in whatever activity the user is and if the task was launched from another activity. I tried putting a reference in the application class to the progressbar and then refresh it in the activities in the oncreate and onrestart,that the way the task will always have the refreshed reference on the postexecute method Any inconvinients on this procedure? regards, On Fri, Sep 23, 2011 at 7:13 PM, blake blake.me...@gmail.com wrote: AsyncTasks are a nifty tool but they have a fairly limited specific set of uses. The previous responses have pointed out a several problems with this code: you can't keep static refs to Activites or Views, multiple Activities can't share a progress bar, etc. I don't understand the use case, but I agree with Mark that, from the code you've supplied, this might be better done as an IntentService or as a pair of Fragments. I'm going to be giving a Webinar on the pitfalls surrounding AsyncTasks next week, on the 29th: http://oreillynet.com/pub/e/2061 -blake Programming Android, FTW! http://oreilly.com/catalog/0636920010364 -- 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