Reputation: 13
I have one activity 'A' which extends mapActivity which calls service 'B', and Service 'B' which extends service. I'am getting Latitude and Longitude in service 'B'. Now i need to call the method in Activity 'A' and pass the Latitude and Longitude contineosly as soon as the location is updated. In that method I have code to display the Location. Thanks in advance..
Upvotes: 1
Views: 247
Reputation: 68167
You cant get reference of your Activity from Service unless you set a STATIC
reference to it - which is highly not recommended and is considered to be a culprit for memory leak issues.
Instead, I would suggest you to make use of android's broadcasting mechanism using context.sendBroadcast
and BroadcastReceiver
.
Upvotes: 1
Reputation: 1006539
How to Call Method of one activity from service in Android?
You don't.
Either:
Service
in the first place (with all the logic within the activity), orLocalBroadcastManager
to send a message from the service to the activity, orMessenger
to send a message from the service to the activity, orPendingIntent
created by createPendingResult()
on the activity to send a message from the service to the activity, orResultReceiver
, or the Otto library, or a variety of other means to send a message from the service to the activityUpvotes: 2