latata
latata

Reputation: 1723

Communication between broadcast receiver and service

I just want to know what should I look for to manage with my problem. I want to make an application which download some data from the internet and save it to file. During downloading application should receive SMS message which should contain some important data. I have service which is run from AlarmManager and I have BroadcastReceiver which can receive sms. I want to know how to send data from SMS receiver (BroadcastReceiver) to the service?

Upvotes: 0

Views: 1462

Answers (1)

fedepaol
fedepaol

Reputation: 6862

You added an IntentService tag to the question so I assume you are using an intent service to perform the request.

What I would do in your place is to use a regular service and to host a local (not declared in the manifest) broadcast receiver inside it.

You can then perform the download in a different thread hosted in the service itself. In this way you will have access to the Service class from the broadcast recevier, and if you set the downloader thread / asynctask as an inner class you can let them communicate.

This will change a bit the behaviour of your service. You have to let it stopSelf() whereas the intentservice was self contained and dies automatically when it finishes its job.

Upvotes: 3

Related Questions