Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Best background practices
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Federico Paolinelli  
View profile  
 More options Aug 27 2010, 5:24 pm
From: Federico Paolinelli <fedep...@gmail.com>
Date: Fri, 27 Aug 2010 14:24:03 -0700 (PDT)
Local: Fri, Aug 27 2010 5:24 pm
Subject: Best background practices
Hi all, my application needs to perform some activities in background
(like interacting with the network and check the location and some
other stuff), having or not the main activity visible.

Which is the best way to achieve this? Should I write a service for
each kind of job? Or just one service that performs everything?

I am aware that I will need to launch threads / asynctasks in any case
because the service runs on the same thread of the ui, but maybe
having several services is a more clear and readable structure...

Thanks to everybody.

    Federico


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Maps.Huge.Info (Maps API Guru)  
View profile  
 More options Aug 27 2010, 5:58 pm
From: "Maps.Huge.Info (Maps API Guru)" <cor...@gmail.com>
Date: Fri, 27 Aug 2010 14:58:51 -0700 (PDT)
Local: Fri, Aug 27 2010 5:58 pm
Subject: Re: Best background practices
I think the consensus is that AsyncTask is the way to go if what
you're trying to do affects the UI thread eventually. Using a service
to compute location for instance would be over complicated.

-John Coryat


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Federico Paolinelli  
View profile  
 More options Aug 28 2010, 6:33 am
From: Federico Paolinelli <fedep...@gmail.com>
Date: Sat, 28 Aug 2010 03:33:54 -0700 (PDT)
Local: Sat, Aug 28 2010 6:33 am
Subject: Re: Best background practices

On 27 Ago, 23:58, "Maps.Huge.Info (Maps API Guru)" <cor...@gmail.com>
wrote:

> I think the consensus is that AsyncTask is the way to go if what
> you're trying to do affects the UI thread eventually. Using a service
> to compute location for instance would be over complicated.

> -John Coryat

Maybe I didn't explain correctly:
If I need to react to some location change for example, and notify the
user, I can't use _just_ an async thread. I need to to all the logic
in a service and throw for example a notification plus a broadcast
that will update the ui if it is on top.
What I was asking is: if I need to perform more than one task in
background (I mean when the phone screen is off, or when the user is
reading the times website while sitting on the toilet), does it make
any sense to create more than one service? Or should I just create one
service that performs many task like listening on the network as well
as being notified of position changes?

Federico


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frank Weiss  
View profile  
 More options Aug 28 2010, 12:32 pm
From: Frank Weiss <fewe...@gmail.com>
Date: Sat, 28 Aug 2010 09:32:34 -0700
Local: Sat, Aug 28 2010 12:32 pm
Subject: Re: [android-developers] Re: Best background practices
I suppose you'd be better off with a service per service instead of
one god service. The reason is that it make the code cleaner - you
don't need to manage multiple alarms and network connections in one
class. An exception would be a service that just does one kind of
thing, but handles a queue of requests. To avoid copy and pasting
common code, use a common abstract base class that extends Service.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Federico Paolinelli  
View profile  
 More options Aug 28 2010, 1:01 pm
From: Federico Paolinelli <fedep...@gmail.com>
Date: Sat, 28 Aug 2010 10:01:12 -0700 (PDT)
Local: Sat, Aug 28 2010 1:01 pm
Subject: Re: Best background practices
On 28 Ago, 18:32, Frank Weiss <fewe...@gmail.com> wrote:

> I suppose you'd be better off with a service per service instead of
> one god service. The reason is that it make the code cleaner - you
> don't need to manage multiple alarms and network connections in one
> class. An exception would be a service that just does one kind of
> thing, but handles a queue of requests. To avoid copy and pasting
> common code, use a common abstract base class that extends Service.

Ok, it's what I wanted to do. One thing that I'd like to get better
explained is: I am aware that the service(s) run on the same thread of
the ui, so if I have more than one thread will they share the same
thread?? If they listen to the same broadcast for example, will the
intent be queued and served from one service at the time?

It's just curiosity, I know that the time consuming operations must be
performed in async tasks or threads.

Thanks


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Frank Weiss  
View profile  
 More options Aug 28 2010, 1:25 pm
From: Frank Weiss <fewe...@gmail.com>
Date: Sat, 28 Aug 2010 10:25:17 -0700
Local: Sat, Aug 28 2010 1:25 pm
Subject: Re: [android-developers] Re: Best background practices
I'm not a total expert on this...

Threads are really just a way of running multiple stacks/program
counters in the same address space. It's fair to assume they are
time-sliced. Services and Activities are run in a single UI thread
(AFAIK) and the precessing model is typical UI thread which calls
event methods on them sequentially (they don't really run like
classical processes). AsyncTasks run from a thread pool. The first few
can run concurrently, but after that the next one can't start until
another one is finished. Network connections are also pooled (AFAIK),
so that after you open a few, additional ones queue up.

To get workable background processing/networking, you'll probably need
to use alarms/saved state, since an app's process can be summarily
dismissed any time by the OS when other apps need resources. Although
some background processing that takes just seconds you might as well
do with an AsyncTask in an activity instead of a service.

Don't expect SDK apps to get any processing done when the device is
sleeping or turned off (I'm sure you know that already).


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Federico Paolinelli  
View profile  
 More options Aug 28 2010, 1:42 pm
From: Federico Paolinelli <fedep...@gmail.com>
Date: Sat, 28 Aug 2010 19:42:21 +0200
Local: Sat, Aug 28 2010 1:42 pm
Subject: Re: [android-developers] Re: Best background practices

Thanks a lot.  I just needed to know that my direction was the good one.

Federico


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »