Closed shankari closed 3 years ago
We need to initialize the google API client in here. Otherwise, the service could be started twice, so we would create two clients, and by the time the first one calls onConnected(), our instance variable may have switched to the un-connected one. So we will try to use our instance variable, which will crash.
What should we do about the other instance variables? Let's think through it.
The other variables cannot really be moved to onCreate mTransition: this depends on the intent passed in for the start mCurrState: this needs a context to be read from
I do see a similar issue with using instance variables to pass things around, though. if we are started twice, with two different transitions, they will overwrite each other and some transitions may be missed.
How do we pass information to the onConnected callback?
A better option might be to use blockingConnect. https://developers.google.com/android/reference/com/google/android/gms/common/api/GoogleApiClient#blockingConnect()
The challenge is that this cannot be called in the UI thread, so we need to call it from a separate thread. These are pretty simple fixes, but it is pretty scary to be making these changes at the last minute without enough time to test them.
I am going to leave this unchanged for now - it's been working fine on android until now - make the changes on Friday and test them out over the weekend.
I will only fix the move to onCreate, which is really simple
because an alternative is to store all the pending actions in a queue and handle all of them on connect.
we have moved to the new GoogleApiClient which manages the connection logic internally https://github.com/e-mission/e-mission-data-collection/commit/b7ceceefa2899d40c6d2a58ce472a2b2c1168df4 and https://github.com/e-mission/e-mission-data-collection/commit/8363241c8dac06fe8f980c9332fe287c91f8ebce