The ServiceStartArguments API demo is one example of associating a
thread with a service:

http://code.google.com/android/samples/ApiDemos/src/com/google/android/samples/app/ServiceStartArguments.html

On Apr 26, 9:46 pm, "Dan U." <[EMAIL PROTECTED]> wrote:
> I think what Hielko said still applies. Try experimenting a bit with
> it. If you get stuck, just post another message.
>
> On Apr 26, 2:35 pm, WildLuka <[EMAIL PROTECTED]> wrote:
>
> > follow the thread link at the beginning of my first post ... it's all
> > there
>
> > On Apr 26, 11:14 pm, Hielko <[EMAIL PROTECTED]> wrote:
>
> > > I'm not sure what problem you exactly want to solve. If you want a
> > > service that is running in it's own thread you can simple create a
> > > class that extends Service and implements runnable (and in the
> > > onCreate of the service you create the thread): so what's the problem?
>
> > > On 26 apr, 22:49, WildLuka <[EMAIL PROTECTED]> wrote:
>
> > > > supposing you have a service with an certain number of methods and the
> > > > service is to run in its own thread ... how would you do it ?
>
> > > > On Apr 26, 10:41 pm, "Dan U." <[EMAIL PROTECTED]> wrote:
>
> > > > > If you notice the api docs say that creating a Handler associates it
> > > > > with the current thread. Probably you create your Handler instance
> > > > > while setting up the UI? That should mean the UI thread is what it
> > > > > uses when you use your Handler. That would explain why you have a
> > > > > frozen UI. Quite often a Handler is used for making changes to the UI,
> > > > > so having it run on the UI thread is the most common use case in my
> > > > > opinion. I think for your example, you don't even need to use a
> > > > > Handler. I'd just utilize a Thread directly.
>
> > > > > On Apr 26, 1:24 pm, WildLuka <[EMAIL PROTECTED]> wrote:
>
> > > > > > hello there,
>
> > > > > > I have been trying to provide an answer to one of my own questions,
> > > > > > you can see it 
> > > > > > here:http://groups.google.com/group/android-developers/browse_thread/threa...
>
> > > > > > so I have created a service an inner class that extends Handler.
> > > > > > here is the class:
>
> > > > > >         private class ServiceHandler extends Handler {
>
> > > > > >                 Session login(final String username, final String 
> > > > > > password, final
> > > > > > ActivityPendingResult result) {
> > > > > >                         post(new Runnable() {
> > > > > >                                 public void run() {
> > > > > >                                         long id = 
> > > > > > Thread.currentThread().getId();
> > > > > >                                         // login code here.
> > > > > >                                         // creation of Session 
> > > > > > object
> > > > > >                                 }
> > > > > >                         });
> > > > > >                         return mSession;
> > > > > >                 }
>
> > > > > >                 public void handleMessage(Message msg) {
> > > > > >                         int what = msg.what;
> > > > > >                         switch(msg.what) {
> > > > > >                         case 0:
> > > > > >                                 ActivityPendingResult result = 
> > > > > > (ActivityPendingResult) msg.obj;
> > > > > >                                 result.sendResult(0, null, null);
> > > > > >                                 break;
> > > > > >                         default: break;
> > > > > >                         }
> > > > > >                 }
> > > > > >         }
>
> > > > > > the hadler.login() method gets called by the login method declared 
> > > > > > in
> > > > > > the Service class.
> > > > > > The Service.login method is called by an Activity method. What 
> > > > > > puzzles
> > > > > > me is that i was expecting handler.post() to spawn a new thread, and
> > > > > > turn the whole login process into an asynchronous one, instead the
> > > > > > thread id is 1 and as a result the interface on the Activity is
> > > > > > frozen.
> > > > > > what's going on here ?
>
> > > > > > take care
> > > > > > luka- Tekst uit oorspronkelijk bericht niet weergeven -
>
> > > > - Tekst uit oorspronkelijk bericht weergeven -
--~--~---------~--~----~------------~-------~--~----~
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
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to