Same state in two different activities in Android

127 Views Asked by At

I'm currently developing an Android application with BLE (Bluetooth Low Energy) API basead on app distributed by Google Developers.

At this moment i already find devices, connect and receive notifications by slave (CC2540 TI).

My general propose is: I have an activity "A" that connects and shows at every 1second the received notifications (data string) and I want to move to activity "B" and continue receiving and visualizing at every 1 second the same data of activity "A", in other words, I want visualize and receive data in real time in more than one activity.

What is the best way/solution for this problem ? I have read about put "extend Application" in my activity B so that access the whole state of activity "A" but i can't.

With intent I only pass to activity "B" one string and not various strings at 1second...

Can you help me ? I appreciate the attention.

Thanks a lot. Best Regards

1

There are 1 best solutions below

1
On

You can create a class that manages the BLE connection that belongs to a class that extends Application. Create a get() method in the Application class so you can retrieve the class that manages the BLE connection in any Activity. I have an example project that does this with a Service (that I run a BLE connection within), but it is the same concept. It is intended to allow you to share BLE connections between Activities.

Project Example