Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintaining Connection Between Activities #21

Open
chirag-s opened this issue Jun 14, 2020 · 1 comment
Open

Maintaining Connection Between Activities #21

chirag-s opened this issue Jun 14, 2020 · 1 comment

Comments

@chirag-s
Copy link

Hi could you suggest the ideal way to maintain connection between activities.

I am defining the BluetoothController as static in main activity and defining a local as follows
public BluetoothController mBluetoothController = MainActivity.mBluetoothController;

and then using that object i read the incoming data

mBluetoothController.setBluetoothListener(new BluetoothListener() { ... }

This works 90% of the time but i get this error at times
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.x/com.x.yActivity}: java.lang.NullPointerException: Attempt to invoke virtual method 'void co.lujun.lmbluetoothsdk.BluetoothController.setBluetoothListener(co.lujun.lmbluetoothsdk.base.BluetoothListener)' on a null object reference

Do let me know how i can resolve this issue !!

@ghost
Copy link

ghost commented May 12, 2022

The best way to maintain a connection is to use controller API in a Thread/service that is able to survive to the Activity destroy.
Another solution (donno if could be applied to your case) is to implement a single Activity with 2 or more Fragments.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant