Ahmed
Ahmed

Reputation: 15039

Android service runing in background and changing service logic through some UI, how to do that?

I am new to android development. I am creating an android application, in which there is a background service always running..

The service's target is to monitor incoming sms messages and do processing based on message filter

However the user would also want to change service bahviour through some UI/Activity. for exmaple user might wanna change the message filter.

SO in this case would my Service and Activity run as one process or seperate process ?

How would I make them communicate ? Please advise best possible model so that the performance is not affected.

Second question: Does an apk always have one processes or can have multiple processes ??

Thanks,

Upvotes: 0

Views: 352

Answers (2)

NickT
NickT

Reputation: 23873

You might want to look at a Bound Service That page describes how an activity can access methods within a running service in the section 'Extending the binder class'

Upvotes: 0

mcnicholls
mcnicholls

Reputation: 846

By default, all components of your application run in the same process, but it is possible to arrange for different components to run in different processes by using the android:process attribute in the manifest xml. I would strongly recommend against this for what your are doing.

You will want your Activity and Service to run in the same process, but the Service should arrange to have it's own thread to do processing on, otherwise the Service will run in the main UI thread, which you definitely don't want.

You could use the IntentService class to allow your activity to post Intent's to your Service. The IntentService class then queues the Intents up and processes them one at a time on a dedicated worker thread that is managed by IntentService.

Upvotes: 1

Related Questions