1

I want my app to start an activity at any time in response to a "shake" of the phone.

Would it be advisable to have a service constantly running in the background that listens for a change in the accelerometer?

Does anyone have any other way to do this?

There are plenty of apps that do this kind of thing.

1 Answers1

1

Yes, using a service would be the way to go, since your app needs to be running for the SensorEventListener to work.

Check out this answer for some code on how to implement a SensorEventListener (in an activity, but similar code can be used in a service).

Community
  • 1
  • 1
verybadalloc
  • 5,768
  • 2
  • 33
  • 49
  • Thanks. Do you estimate that the SensorEventListener is a battery drainer? – user2498796 Jun 19 '13 at 13:50
  • It might be quite a drainer. I never tried to run it all the time, but you could try to implement some extra logic in your service to unregister the listener every second. Not sure if it would work though. – verybadalloc Jun 19 '13 at 14:00