Fix crash when enabling bluetooth after starting the app#108
Open
Smeat wants to merge 1 commit intovoroshkov:devfrom
Open
Fix crash when enabling bluetooth after starting the app#108Smeat wants to merge 1 commit intovoroshkov:devfrom
Smeat wants to merge 1 commit intovoroshkov:devfrom
Conversation
voroshkov
reviewed
Dec 30, 2019
| if(intent.getIntExtra(BluetoothAdapter.EXTRA_STATE, -1) == BluetoothAdapter.STATE_ON) { | ||
| bt.runService(); | ||
| } else { | ||
| bt.stopService(); |
Owner
There was a problem hiding this comment.
stopping the service on each state change except ON seems not quite safe to me
Contributor
Author
There was a problem hiding this comment.
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"?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When enabling bluetooth after starting the app and trying to connect, the app crashes due to
mChatServicebeing 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.