简体   繁体   中英

Change toggle button state from service

Is it possible to change ToggleButton state (checked/unchecked) from service?
I am passing boolean value via SharedPreference after togglebutton click(checked) and reset it after stop recording at service (service is still running after it).
But how i can change ToggleButton state ?

You can listen sharedprefs changes via OnSharedPreferenceChangeListener . So from service set boolean flag in prefs. Listen for your flag from activity and change toggle button state.

  • You also can use LocalBroadcastManager to send message when you stop recording.
  • Activity can give a callback to a service which it should call when recording it stopped.
  • You can use EvenBus to communicate between app components.

There are a lot different ways.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM