0

So what is the best way to send data received in the main activity to a fragment, currently the app gets around 20 data per second via BLE, last version used to have a single activity and worked fine, now i added a ViewPager so I could extend the UI and use 2 fragments, but i can't find a way to send that data to the fragment to work with it(Buttons updates and gauges updates). Any suggestion on having an optimal data transfer from main activity to the current selected fragment?

1 Answers1

0

I'm using BroadcastReceivers to solve these kind of problems to avoid problems related to the Android lifecicle.

The basic idea of broadcast receiver is a publisher-subscriber, the interested fragmets should register with an appropriate intent filter to the events they're interested in and the activity should be spamming events.

More about broadcast receivers at https://developer.android.com/reference/android/content/BroadcastReceiver.html

Pato94
  • 784
  • 5
  • 6