I am building one of those SOS apps. Whenever the device is shaken above a threshold value (detected through accelerometer), I am showing a Toast
(as of now)
1) App is launched. User gives name, email, etc.. and clicks finish
on last screen.
2) Service
is started which keeps listening for shake.
3) It detects the shake correctly if the App is running.
4) If I close the app (the activity
), the service gets killed along with it.
How do I keep the service
running even if app is closed, so that it can listen to shakes from background? (That's the whole purpose of this app)
[1.I am returning START_STICKY in onStartCommand
I also tried using a
BroadcasterReciever
which will restart service by receiving broadcast fromonTaskRemoved
I am testing on ASUS Xenfone Max, Marshmallow OS ]