No please please do NOT run things in a separate process for this.  That is
a huge waste, for no reason.

Since the sensor API is all callback based, there is no problem here.  The
callbacks will happen on the main thread.  The main thread should always be
responsive.  No problem.  If your other service has some long-running task,
then do it on another thread (or use IntentService or AsyncTask or
whatever).  As long as you follow the general rule of not doing long running
work on the main thread of the process, things will be fine.

On Fri, Apr 8, 2011 at 12:24 AM, gjs <garyjamessi...@gmail.com> wrote:

> Hi,
>
> Services can run in there own separate processes if necessary & you
> can also start & run more threads in a service.
>
> http://developer.android.com/guide/topics/manifest/service-element.html
>
> Regards
>
>
> On Apr 8, 2:04 am, declantraynor <dec...@gmail.com> wrote:
> > Hi,
> >
> > I'm currently building some movement-detection functionality into my
> > application. I haven't found a way of continually monitoring the
> > accelerometer without keeping the phone awake all the time. In trying
> > to overcome this, I currently have a Service implementing
> > SensorEventListener. I can start this service at intervals (using
> > alarm manager), get readings from the device acclerometer, determine
> > if the device is moving, and then shut down the service. Generally,
> > this appears as follows:
> >
> > public class MyService extends Service implements SensorEventListener
> > {
> >
> >     @Override
> >     public void onCreate() {
> >         super.onCreate();
> >     }
> >
> >     @Override
> >     public int onStartCommand(Intent intent, int flags, int startId) {
> >         super.onStartCommand(intent, flags, startId);
> >         /* Register this SensorEventListener with Android sensor
> > service */
> >         return START_STICKY;
> >     }
> >
> >     @Override
> >     public IBinder onBind(Intent intent) {
> >         return null;
> >     }
> >
> >     @Override
> >     public void onDestroy() {
> >         /* Unregister SensorEventListener */
> >         }
> >
> >     /* SensorEventListener Implementation ************************/
> >
> >     @Override
> >     public void onAccuracyChanged(Sensor sensor, int accuracy) {}
> >
> >     /* Receives callback when sensor values change */
> >     @Override
> >     public void onSensorChanged(SensorEvent event) {
> >         /* Determine if moving & then call stopSelf() to shut service
> > down */
> >     }
> >
> > }
> >
> > I have a further problem, however, in that my application has a second
> > service which is invoked on a different schedule. As far as I know,
> > both of the services will be run in the same thread, which is not good
> > as they could conflict.
> >
> > I need to know if there is a safe way to run more than one service
> > simultaneously within the same application. I have considered the use
> > of IntentService instead of the standard Service class. I am aware
> > that these implement their own worker thread for handling invocations.
> > The problem there is that I have no idea how I can implement the type
> > of asynchronous callbacks required by SensorEventListener from within
> > an IntentService. To put it another way, I have no guarantee that a
> > method like onSensorChanged will receive a callback before
> > IntentService completes its work and shuts down.
> >
> > Any suggestions on a workaround to this problem are highly
> > appreciated.
> >
> > Thanks, Declan
>
> --
> 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
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en
>



-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

-- 
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
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to