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

Fix crash when enabling bluetooth after starting the app #108

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from

Conversation

Smeat
Copy link
Contributor

@Smeat Smeat commented Jul 15, 2019

When enabling bluetooth after starting the app and trying to connect, the app crashes due to mChatService being null.
This adds a listener to the bluetooth state and starts the bluetooth service when the user enables bluetooth.

I never did much in Android, so I hope implementing it this way is correct.

@voroshkov voroshkov changed the base branch from master to dev December 29, 2019 10:24
if(intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) {
bt.runService();
} else {
bt.stopService();
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

stopping the service on each state change except ON seems not quite safe to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BluetoothAdapter.EXTRA_STATE can be either be STATE_OFF, STATE_TURNING_ON, STATE_ON or STATE_TURNING_OFF. In each case except STATE_ON we want the service to be stopped to avoid any invalid state and cover all edge cases. It is correct, that we might be stopping the service several times, but stopping an already stopped service shouldn't change the program state at all.

Stopping the service multiple times, seems even more safe to me, so I am not sure what you mean by "seems not quite safe to me"?

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

Successfully merging this pull request may close these issues.

2 participants