Lin S
Lin S

Reputation: 63

Suggestions for transferring int value from Service to MainActivity?

I have a Service that is started from a pendingIntent.

This service gives either a 1 or 2 int (there's a notification that contains a button, that once pressed returns 1 then 2 over and over.) Need to transfer this int to my mainActivity to then say (in my mainActivity)- if (ServiceClass.getNum ==1) then mToggle.setChecked(true) else (false).

I heard a bunch of different suggestions on how to do this. Some of those suggestions include Binding to the activity, using a Local Broadcast receiver? Also my mToggle button needs to still be able to change states even if the Activity is in the background or closed.

Any suggestions on the best course of action is appreciated.

Upvotes: 0

Views: 38

Answers (1)

minfo
minfo

Reputation: 129

For communicating between Android activity and service we can use broadcast receiver. you can see this https://developer.android.com/guide/components/broadcasts

Upvotes: 1

Related Questions