android-developers
[Arriba] [Todas las Listas]

Re: [android-developers] Cuestión de diseño del juego: múltiple handl

To: android-developers@xxxxxxxxxxxxxxxx
Subject: Re: [android-developers] Cuestión de diseño del juego: múltiple handlers
From: Kostya Vasilyev <kmansoft@xxxxxxxxx>
Date: Wed, 30 Nov 2011 19:48:36 +0400
Delivery-date: Wed, 30 Nov 2011 10:49:03 -0500
Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlegroups.com; s=beta; h=x-beenthere:received-spf:mime-version:in-reply-to:references:date :message-id:subject:from:to:x-original-sender :x-original-authentication-results:reply-to:precedence:mailing-list :list-id:x-google-group-id:list-post:list-help:list-archive:sender :list-subscribe:list-unsubscribe:content-type; bh=7djv+fY5Yg2x3uITRAeg1UVeRlQw+lEkyT6MCbNPOzg=; b=S/LdLMVm0HCoLf2C7lCGHlhbok8RhEyYtbP6H7j4iaxNzawB+BWSg6CIv5hDBlR3K6 NHJDN0aUvAWlVi7DiKE+8BBoo6dEERQAPmVeyJm6bvyO5Cz3LUvBzu1y6hzHMg3uSImU qRRjV1wKRsAdB94I+2zlfqZUqskP5qyQ3jH+Y=
Envelope-to: traductor@xxxxxxxxxxx
In-reply-to: <CAA_CB1K2RTx+NL+6X9zS38LVx6j5Gb88xjGge6QF1hNXLinc0g@mail.gmail.com>
List-archive: <http://groups.google.com/group/android-developers?hl=en_US>
List-help: <http://groups.google.com/support/?hl=en_US>, <mailto:android-developers+help@googlegroups.com>
List-id: <android-developers.googlegroups.com>
List-post: <http://groups.google.com/group/android-developers/post?hl=en_US>, <mailto:android-developers@googlegroups.com>
List-subscribe: <http://groups.google.com/group/android-developers/subscribe?hl=en_US>, <mailto:android-developers+subscribe@googlegroups.com>
List-unsubscribe: <http://groups.google.com/group/android-developers/subscribe?hl=en_US>, <mailto:android-developers+unsubscribe@googlegroups.com>
Mailing-list: list android-developers@xxxxxxxxxxxxxxxx; contact android-developers+owners@xxxxxxxxxxxxxxxx
References: <CAA_CB1K07u3G6K=G=gf+RDeWRXy5qBA5iJd2JnrTL-Efq1046A@mail.gmail.com> <CANCScghHsHGMZwmdSXLm2yJr+ayeJPMe1-X5sYoUZBx6FSjp=g@mail.gmail.com> <CAA_CB1KoNkpa-q0ga-DLdQrrQRQSKu7y5rZC6GyV2Z5b-2QFOQ@mail.gmail.com> <CAA_CB1+_GYzy78Q_EXEsvJnVgcCGxz01yFgRezpOS39-4bz3Pw@mail.gmail.com> <CAN7dqjDpcHQOz6UMi-rgk1rQ0GxpyKxaR2PzFsu4yYsXuz0NnQ@mail.gmail.com> <CAA_CB1K2RTx+NL+6X9zS38LVx6j5Gb88xjGge6QF1hNXLinc0g@mail.gmail.com>
Reply-to: android-developers@xxxxxxxxxxxxxxxx
Sender: android-developers@xxxxxxxxxxxxxxxx
Un hilo que pretende gastar su *lifetime en un mensaje *dispatching necesidades
de bucle para llamar *Looper.Prepara() antes de ir a *Looper.Bucle().

*http://*developer.*android.*com/Referencia/*android/*os/*Looper.*html

Esto *initializes las estructuras de dato necesitadas por bucle() más tarde. El *UI el hilo
tiene esto hecho por el marco, pero es necesario para vuestro hilo propio.

-- *Kostya

30 ноября 2011 г. 18:15 пользователь John *Goche
<*johngoche99@*xxxxxxxxxxxxxx>написал:

>
> *Thank te para vuestra respuesta, he reestructurado mi código un poco
> y ahora tengo múltiple *handlers en mi código pero no más largo
> conseguir el mensaje de error sobre teniendo que llamar *looper.Prepara()
> (cuál probé llamar sin entender exactamente lo que hace y no consiguió un resultado guapo). *Sorry Si dejé los detalles
> fuera, gasté algunos cronometran reestructurar mi código y entonces era
> incapaz de conseguir el mismo mensaje de error *hence el *vagueness.
>
> Soy todavía interesado en lo que podría haber causado el *orignal el mensaje que
> me dice para llamar *looper.Prepara() aun así y la lógica detrás de él.
>
> *Thanks,
>
> John *Goche
>
>
> 2011/11/30 *Kostya *Vasilyev <kmansoft@xxxxxxxxx>
>
>> Te puede tener cuando muchos *handlers tan necesitado, razonablemente.
>>
>> El trabajo de *dispatching mensajes a *handlers es hecho por *Looper, en todo caso.
>>
>> Y aquello es donde pienso que vuestro asunto original tiene sus raíces.
>>
>> *Posting Un mensaje más exacto que "yo consiguen un error diciendo que necesito llamar preparar *o algo* desde no puedo tener más que un
>> *handler por hilo *o algo*."
>>
>> ( Soy bastante seguro lo que es, pero dejado ver el mensaje primero )
>>
>> -- *Kostya
>>
>> 30 ноября 2011 г. 16:35 пользователь John *Goche <
>> *johngoche99@*xxxxxxxxxxxxxx> написал:
>>
>>
>>> También, por qué  ser mejor de tener un *handler que múltiple *handlers
>>> *anyways
>>> dado que en algunas situaciones múltiples *handlers lata *compile?
>>>
>>>
>>> En *Wed, *Nov 30, 2011 en 1:32 PM, John *Goche <*johngoche99@*xxxxxxxxxxxxxx>escribió:
>>>
>>>>
>>>> *Thank tú *TreKing para vuestro consejo,
>>>>
>>>> Pero entonces en mi *handleMessage tendría que comprobar con si
>>>>
>>>> (*inst caso de *Foo)
>>>>   *inst.*foocallback();
>>>> Más si (*inst *instanceof Barra)
>>>>   *inst.*barcallback();
>>>> Más si (...)
>>>>
>>>> O es allí un *neater solución, quizás utilizando *polymorphism o un patrón
>>>> de diseño de alguna clase
>>>> de modo que mi *handleMessage  no deprisa vuelta a un desorden?
>>>>
>>>> *Thanks,
>>>>
>>>> John *Goche
>>>>
>>>>
>>>>
>>>> En *Tue, *Nov 29, 2011 en 11:02 PM, *TreKing <trekingapp@xxxxxxxxx> escribió:
>>>>
>>>>> En *Tue, *Nov 29, 2011 en 3:46 PM, John *Goche <
>>>>> *johngoche99@*xxxxxxxxxxxxxx> escribió:
>>>>>
>>>>>> El número de *sprites es indefinido (podría variar en número) pero cada cual
>>>>>> necesita dirigir él individualmente. Arriba de esto el mundo tiene su
>>>>>> propio *handler para dirigir actualiza a él.
>>>>>>
>>>>>
>>>>> No necesitas separado *handlers, puedes pasar el caso del
>>>>> objeto que está siendo actualizado en el *handler mensaje, entonces uso un solo
>>>>> *handler para el hilo principal.
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------------------------------------
>>>>> *TreKing <*http://Sitios.*google.*com/Sitio/*rezmobileapps/*treking> -
>>>>> *Chicago *transit *tracking *app para *Android-*powered dispositivos
>>>>>
>>>>>  --
>>>>> recibiste este mensaje porque eres *subscribed al *Google
>>>>> Grupos "*Android *Developers" grupo.
>>>>> A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
>>>>> 
>>>>> A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx
>>>>> 
>>>>> Puesto que más opciones, visita este grupo en
>>>>> *http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
>>>>
>>>>
>>>>
>>>  --
>>> Recibiste este mensaje porque eres *subscribed al *Google
>>> Grupos "*Android *Developers" grupo.
>>> A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
>>> A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx
>>> 
>>> Puesto que más opciones, visita este grupo en
>>> *http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
>>>
>>
>>  --
>> Recibiste este mensaje porque eres *subscribed al *Google
>> Grupos "*Android *Developers" grupo.
>> A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
>> A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx
>> 
>> Puesto que más opciones, visita este grupo en
>> *http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
>>
>
>  --
> Recibiste este mensaje porque eres *subscribed al *Google
> Grupos "*Android *Developers" grupo.
> A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
> A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx
> 
> Puesto que más opciones, visita este grupo en
> *http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
>

-- 
Recibiste este mensaje porque eres *subscribed al *Google
Grupos "*Android *Developers" grupo.
A correo a este grupo, envía *email a *android-developers@xxxxxxxxxxxxxxxx
A *unsubscribe de este grupo, envía *email a *android-*developers+unsubscribe@xxxxxxxxxxxxxxxx

Puesto que más opciones, visita este grupo en
*http://grupos.*google.*com/Grupo/*android-*developers?*hl=*en
A thread that intends to spend its lifetime in a message dispatching loop
needs to call Looper.prepare() before going into Looper.loop().

http://developer.android.com/reference/android/os/Looper.html

This initializes the data structures needed by loop() later. The UI thread
has this done by the framework, but it's necessary for your own thread.

-- Kostya

30 ноября 2011 г. 18:15 пользователь John Goche
<johngoche99@xxxxxxxxxxxxxx>написал:

>
> Thank you for your reply, I've restructured my code a little bit
> and now I do have multiple handlers in my code but no longer
> get the error message about having to call looper.prepare()
> (which I tried calling without understanding exactly what it
> does and didn't get a nice result). Sorry if I left the details
> out, I spent some time restructuring my code and then was
> unable to get the same error message hence the vagueness.
>
> I'm still interested in what might have caused the orignal message
> telling me to call looper.prepare() though and the logic behind it.
>
> Thanks,
>
> John Goche
>
>
> 2011/11/30 Kostya Vasilyev <kmansoft@xxxxxxxxx>
>
>> You can have as many handlers as needed, within reason.
>>
>> The work of dispatching messages to handlers is done by Looper, anyway.
>>
>> And that's where I think your original issue has its roots.
>>
>> Posting a more exact message than "I get an error saying I need to
>>
>> call prepare *or something* since I cannot have more than one
>> handler per thread *or something*."
>>
>> ( I am pretty sure what it is, but let's see the message first )
>>
>> -- Kostya
>>
>> 30 ноября 2011 г. 16:35 пользователь John Goche <
>> johngoche99@xxxxxxxxxxxxxx> написал:
>>
>>
>>> Also, why would it be better to have one handler than multiple handlers
>>> anyways
>>> given that in some situations multiple handlers can compile?
>>>
>>>
>>> On Wed, Nov 30, 2011 at 1:32 PM, John Goche <johngoche99@xxxxxxxxxxxxxx>wrote:
>>>
>>>>
>>>> Thank you TreKing for your advice,
>>>>
>>>> But then in my handleMessage I would have to check with
>>>>
>>>> if (inst instance of Foo)
>>>>   inst.foocallback();
>>>> else if (inst instanceof Bar)
>>>>   inst.barcallback();
>>>> else if (...)
>>>>
>>>> or is there a neater solution, perhaps using polymorphism or a design
>>>> pattern of some sort
>>>> so that my handleMessage does not quickly turn into a mess?
>>>>
>>>> Thanks,
>>>>
>>>> John Goche
>>>>
>>>>
>>>>
>>>> On Tue, Nov 29, 2011 at 11:02 PM, TreKing <trekingapp@xxxxxxxxx> wrote:
>>>>
>>>>> On Tue, Nov 29, 2011 at 3:46 PM, John Goche <
>>>>> johngoche99@xxxxxxxxxxxxxx> wrote:
>>>>>
>>>>>> The number of sprites is indefinite (could vary in number) but each
>>>>>> needs to manage itself individually. On top of this the world has its
>>>>>> own handler to manage updates to itself.
>>>>>>
>>>>>
>>>>> You don't need separate handlers, you can pass the instance of the
>>>>> object that is being updated in the handler message, then use one single
>>>>> handler for the main thread.
>>>>>
>>>>>
>>>>> -------------------------------------------------------------------------------------------------
>>>>> TreKing <http://sites.google.com/site/rezmobileapps/treking> -
>>>>> Chicago transit tracking app for Android-powered devices
>>>>>
>>>>>  --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "Android Developers" group.
>>>>> To post to this group, send email to
>>>>> android-developers@xxxxxxxxxxxxxxxx
>>>>> To unsubscribe from this group, send email to
>>>>> android-developers+unsubscribe@xxxxxxxxxxxxxxxx
>>>>> 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@xxxxxxxxxxxxxxxx
>>> To unsubscribe from this group, send email to
>>> android-developers+unsubscribe@xxxxxxxxxxxxxxxx
>>> 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@xxxxxxxxxxxxxxxx
>> To unsubscribe from this group, send email to
>> android-developers+unsubscribe@xxxxxxxxxxxxxxxx
>> 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@xxxxxxxxxxxxxxxx
> To unsubscribe from this group, send email to
> android-developers+unsubscribe@xxxxxxxxxxxxxxxx
> 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@xxxxxxxxxxxxxxxx
To unsubscribe from this group, send email to
android-developers+unsubscribe@xxxxxxxxxxxxxxxx
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
<Anterior por Tema] Tema Actual [Siguiente por Tema>