doInBackground like you have it is not the way to do that -- what you
have coded is called spinning

Kostya Vasilyev's explanation is clearer than mine and will move you
in the direction of correct code if you take the suggestion and
continue to work it but rather than doing a spin-lock as a wait we use
instead a programming approach known as interfaces - sometimes called
callbacks - which will be in the AsyncTask documents

rather than detaching what you do is call dot start on AsyncTask (a
form of Threading) and let it run

If it ( the program ) has to callback to the User Interface then use
of AsyncTask needs to have the UI element in it that the UI thread
will call into

If background thread does not need UI to then dont really need
AsyncTask but need a service or something instead

you can pass object references to some forms of background processing
which then can set a var in the AsyncTask based class from background
processing or there are callbacks / interfaces in some supplied
classes that are meant for that

Google I/O 2010 - Writing zippy Android apps

http://developer.android.com/videos/index.html#v=Oq05KqjXTvs

the guy talks fast by most people but seems rather simple to me -- you
fix this stuff now or get blown off the sidewalk later by an NPE when
IntentService.onBind (Intent intent) default implementation returns
null but you decided not to implement android:maxSdkVersion

to do this work you have to keep clear in your mind that a Thread
( from wherever it came ) is an instruction pointer in whatever is
driving the code ( which usually is a processor ) then the whole thing
becomes remarkably simple

surprisingly for those who have not bit the dust on it several times
one can do an amazing amount just by making all method calls
synchronized or using synchronizaton blocks -- you will see in most
accomplished code a style of code design Object lock = new Object()
and you just barrier on that

On Nov 18, 9:40 pm, Bluemercury <[email protected]> wrote:
> Hi there! Sorry for posting here again, but i was hoping if i could try
> this sample, you said to put the synchronized in the detach method here:
>
> void detach() {
> *activity=null;*
>
> }
>
> in the asynctask, is this correct?but detach() is only called in the
> activity and not the in the async task itself, i thought synchronized
> methods assumed that they're both launched from 2 different threads....but
> in this case the activity(UI thread) calls the detach method like you said,
> but the async task doesnt, only the attach method...

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to