[android-developers] Re: about Async Task

2011-08-18 Thread Streets Of Boston
You mean you do NOT want to execute the same task twice (e.g. when the user 
clicks a button two or more times in quick succession)?

If so, then disable the button until the AsyncTask has finished. 
You know when it's finished by implementing/overriding the onPostExecute 
method and from there you can enable that button again.

-- 
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: about Async Task

2011-08-18 Thread Andrew Pittman
Yes, usually AsyncTask is only able to be run once. Restarting the same task
may give you a little trouble though due to this. If you have something that
needs to run over and over again I would suggest that you look into starting
a service and loop the task you need to keep running in its own thread and
just make it sleep for the needed amount of time. As long as you have the
activity running in its own thread in a service you can loop it and make it
repeat infinitely as long as you allow the service to run.

On Thu, Aug 18, 2011 at 8:30 AM, Streets Of Boston
flyingdutc...@gmail.comwrote:

 You mean you do NOT want to execute the same task twice (e.g. when the user
 clicks a button two or more times in quick succession)?

 If so, then disable the button until the AsyncTask has finished.
 You know when it's finished by implementing/overriding the onPostExecute
 method and from there you can enable that button again.

  --
 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: about Async Task

2011-08-18 Thread hectordu...@yahoo.com
thank you guys for help :-)

On Aug 18, 10:36 am, Andrew Pittman kingwils...@gmail.com wrote:
 Yes, usually AsyncTask is only able to be run once. Restarting the same task
 may give you a little trouble though due to this. If you have something that
 needs to run over and over again I would suggest that you look into starting
 a service and loop the task you need to keep running in its own thread and
 just make it sleep for the needed amount of time. As long as you have the
 activity running in its own thread in a service you can loop it and make it
 repeat infinitely as long as you allow the service to run.

 On Thu, Aug 18, 2011 at 8:30 AM, Streets Of Boston
 flyingdutc...@gmail.comwrote:

  You mean you do NOT want to execute the same task twice (e.g. when the user
  clicks a button two or more times in quick succession)?

  If so, then disable the button until the AsyncTask has finished.
  You know when it's finished by implementing/overriding the onPostExecute
  method and from there you can enable that button again.

   --
  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: about Async Task

2011-08-17 Thread Streets Of Boston
Then create a subclass of AsyncTask that does the same thing in the 
background.
Then each time create a new instance of that subclass and call 'execute()' 
on it.

-- 
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: about Async Task

2011-08-17 Thread hectordu...@yahoo.com
yes, that's what i do,
but it  is not clear for me, what means task can be executed only
once, if we suposse to do it exactly the opossite way ..

On Aug 17, 3:34 pm, Streets Of Boston flyingdutc...@gmail.com wrote:
 Then create a subclass of AsyncTask that does the same thing in the
 background.
 Then each time create a new instance of that subclass and call 'execute()'
 on it.

-- 
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: about Async Task

2011-08-17 Thread Streets Of Boston
That means you can only call 'execute()' on an AsyncTask instance once.

E.g.
*MyAsyncTask myTask = new MyAsycnTask();*
*myTask.execute(); // ok*
*myTask.execute(); // wrong. Cannot be executed more than once.*

However:
*MyAsyncTask myTask = new MyAsycnTask();*
*myTask.execute(); // ok*
*myTask = new MyAsycnTask(); // create another new instance of MyAsyncTask
*
*myTask.execute(); // ok*

-- 
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: about Async Task

2011-08-17 Thread Mark Murphy
On Wed, Aug 17, 2011 at 5:26 PM, hectordu...@yahoo.com
hectordu...@yahoo.com wrote:
 yes, that's what i do,

This claim runs counter to:

 but it  is not clear for me, what means task can be executed only
 once, if we suposse to do it exactly the opossite way ..

No, you are not supposed to do it exactly the opossite [sic] way.
You are supposed to do it the way Streets of Boston indicated.

In other words, you can do this:

MyAsyncTask task=new MyAsyncTask();

task.execute();

// later

task=new MyAsyncTask();
task.execute();

but you cannot do:

MyAsyncTask task=new MyAsyncTask();

task.execute();

// later

// skipping task=new MyAsyncTask(); by trying to reuse the existing instance
task.execute();

You better follow what Streets of Boston tells you to do. He is a
rather large person. :-)

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

_Android Programming Tutorials_ Version 3.9 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: about Async Task

2011-08-17 Thread hectordu...@yahoo.com
ok guys, i  get it .. i suposse so  :-(

so ... considering that the application executes the task instance
after the ocurrence of  an user event (clickable button ...), how it
is supossed to be controlled a double ocurrence of the same user
requirement ... i mean, the user makes double click and the
application tries to execute twice the same requirement (because input
data is the same).

is it something to be controlled just by logical ?
does it have a relationship whit isAlive() method ??

thanks for help!


On Aug 17, 4:36 pm, Mark Murphy mmur...@commonsware.com wrote:
 On Wed, Aug 17, 2011 at 5:26 PM, hectordu...@yahoo.com

 hectordu...@yahoo.com wrote:
  yes, that's what i do,

 This claim runs counter to:

  but it  is not clear for me, what means task can be executed only
  once, if we suposse to do it exactly the opossite way ..

 No, you are not supposed to do it exactly the opossite [sic] way.
 You are supposed to do it the way Streets of Boston indicated.

 In other words, you can do this:

 MyAsyncTask task=new MyAsyncTask();

 task.execute();

 // later

 task=new MyAsyncTask();
 task.execute();

 but you cannot do:

 MyAsyncTask task=new MyAsyncTask();

 task.execute();

 // later

 // skipping task=new MyAsyncTask(); by trying to reuse the existing instance
 task.execute();

 You better follow what Streets of Boston tells you to do. He is a
 rather large person. :-)

 --
 Mark Murphy (a Commons 
 Guy)http://commonsware.com|http://github.com/commonsguyhttp://commonsware.com/blog|http://twitter.com/commonsguy

 _Android Programming Tutorials_ Version 3.9 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