very fast
very fast

Reputation: 21

can I start a service from another service in android?

I am developing an app which will keep track of the time when a user's phone is "not used".

Basically, an app which gets activated as soon as a user presses unlock or in the event of an incoming call. I have written a BroadcastReceiver which notifies a background service to start keeping track of time during which the phone is not being used, and will show the activity as soon as the user presses to lock.

My problem is that the services sometimes gets shut down without notifying. Can I write one more service which can periodically check whether the master service is running and toggle it in case it's shutdown? Or is there any other better way to do so?

Upvotes: 1

Views: 5634

Answers (3)

OzgurGundogan
OzgurGundogan

Reputation: 73

Yes you can start another services within your service. Actually you always do this but you are not aware of it. I mean when you call getSystemService(....) initializer in your service , you use another service which is declared by android.

Upvotes: 1

tvshajeer
tvshajeer

Reputation: 1329

A started service can use the startForeground(int, Notification) API to put the service in a foreground state, where the system considers it to be something the user is actively aware of and thus not a candidate for killing when low on memory. (It is still theoretically possible for the service to be killed under extreme memory pressure from the current foreground application, but in practice this should not be a concern.)

Upvotes: 1

M.Baraka
M.Baraka

Reputation: 755

i am not that experienced but yes you should be able to start another service by sending an intent to the other service if you like, service may be killed by the system if it is under heavy memory pressure according to http://developer.android.com/reference/android/app/Service.html.
You should be able to check if your service is running or not.

Upvotes: 0

Related Questions