1

let's say i have 2 activities called Activity A and Activity B

i display list of devices on Activity A that users can connect to. when users clicked one of the devices, it will connected to selected bluetooth device and exchange some data first to verify credentials (i.e. login). i have done this part.

when the data is correct i want to move to Activity B where all the main menu is there but i want to keep that connection made before in Activity A so that i don't need to disconnect and reconnect the connection again.

how to do that ? i'm new about this, please help me..

i use this library for the connection : https://github.com/Polidea/RxAndroidBle

thanks before :)

Nabil Baadillah
  • 319
  • 5
  • 9
  • hi @Nabil Baadillah, I am facing the same problem, if u solved it, then can u share your GitHub repo – Sniffer Feb 15 '21 at 13:53

1 Answers1

1

In principle, I would move all Bluetooth code to a Service. Then you would not be tied to any specific activity.

Robert K.
  • 1,043
  • 1
  • 8
  • 20
  • could you be more specific about that ? i'm still new on this, thanks – Nabil Baadillah Jun 04 '17 at 13:50
  • Create a Service which would be started on app startup and killed when app is off (the second one will be done automatically unless you make it a sticky service). Then do all of the Bluetooth stuff in that Service instead of the Activity, as you do now. This way, your activities will be using Bluetooth from the Service, and nothing will be tied to any of the activities themselves. You can read more about services here: https://www.tutorialspoint.com/android/android_services.htm or here https://developer.android.com/guide/components/services.html – Robert K. Jun 04 '17 at 13:54
  • 1
    You can create a service to do all the bluetooth stuff.And don't forget to use activity by binding to the service..the initial Activity should `startService()` and `bindService()` once second activity is launched it should only `bindService()` – pz64_ Jun 04 '17 at 17:04
  • i finally manage to do that inside service :) thank you for pointing it out (@RobertK. @Pzy64) – Nabil Baadillah Jun 06 '17 at 08:52
  • @NabilBaadillah How did you make it work? can you share your code or github repo? – mudin Jan 11 '18 at 06:35
  • @NabilBaadillah Hey, I am also facing the same issue, during screen navigation from one activity to another BLE device disconnect and I am losing data. Can you please share your code. – Dnveeraj May 22 '23 at 08:20