10 messages in com.googlegroups.android-developersRe: NotifyingService example, is seco...
FromSent OnAttachments
Mark Wyszomierski28 Dec 2007 16:38 
Diogo Ferreira28 Dec 2007 17:20 
Mark Wyszomierski28 Dec 2007 18:22 
Andrew Zhang28 Dec 2007 18:29 
Mark Wyszomierski28 Dec 2007 18:42 
hackbod29 Dec 2007 00:16 
Andrew Zhang29 Dec 2007 00:36 
Mark Wyszomierski29 Dec 2007 11:13 
hackbod29 Dec 2007 23:14 
Mark Wyszomierski30 Dec 2007 08:29 
Subject:Re: NotifyingService example, is secondary thread really necessary?
From:Mark Wyszomierski (mar@gmail.com)
Date:12/28/2007 06:22:14 PM
List:com.googlegroups.android-developers

Yeah that makes sense, thanks Diogo,

Mark

On Dec 28, 8:20 pm, "Diogo Ferreira" <di.@underdev.org> wrote:

I believe the main idea is that the main service thread is free to answer requests and not blocked by data fetching/whatever. As you can imagine a blocked service would ruin not only the service but applications that use it.

On 12/29/07, Mark Wyszomierski <mar@gmail.com> wrote:

Hi,

In my remote service, I want to do some action every N seconds.

For now, I just implemented Runnable:

    public class MyServiceTest extends Service implements Runnable

create a thread in onCreate():

    protected void onCreate()     {         Thread thread = new Thread(null, this, "Test");         thread.start();     }

and then have that thread sleep for N seconds, then do the required tasks:

    public void run()     {         while (true) { // until we are shut down...             try {                 Thread.sleep(5000);             } catch (Exception ex) {}

            Log.i("MyServiceTest", "Checking in from secondary thread..");         }     }

Is this the way google recommends us doing this sort of thing (this is pretty much taken from the NotifyingService example in the SDK). Can we achieve the same thing in the Service's main thread. instead of having this secondary thread doing it?

Thanks, Mark- Hide quoted text -