Fixes for Wear tested on Pixel3 watch#1344
Conversation
1) make activity singletop, otherwise it sometimes starts 2 activites! 2) add extra reading of data if it is missing it seems like there is some sort of life-cycle problem, honestly not 100% sure what, but this fixes the problem.
There was a problem hiding this comment.
Pull request overview
This PR targets Wear OS lifecycle/data-sync issues observed on a Pixel Watch 3 by preventing duplicate MainActivity instances and by re-reading Wear data items when local state appears incomplete.
Changes:
- Set
MainActivitytosingleToplaunch mode to reduce duplicate activity instances. - Add “read data if missing” behavior in
MainActivity/StateServiceto repopulatephoneNode,headers, andtrackerStatewhen absent. - Improve logging/formatting around service connection, data change handling, and connection diagnostics.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| wear/src/main/java/org/runnerup/view/MainActivity.java | Triggers readDataIfMissing() during resume and after service connection; minor formatting changes. |
| wear/src/main/java/org/runnerup/service/StateService.java | Adds conditional data re-read logic and expands connection diagnostics/logging. |
| wear/src/main/AndroidManifest.xml | Sets MainActivity launchMode to singleTop. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| Context.BIND_AUTO_CREATE); | ||
| putDataItem(Constants.Wear.Path.WEAR_APP, true); | ||
| if (mStateService != null) { | ||
| mStateService.readDataIfMissing(); |
There was a problem hiding this comment.
onResume() always calls bindService(...) even if the activity is already bound; if onResume() runs multiple times (common), this can create multiple binds that require matching unbindService(...) calls. Consider guarding the bind with if (!mIsBound) and/or unbinding in onPause()/onStop() to keep bind/unbind balanced.
gerhardol
left a comment
There was a problem hiding this comment.
Not run, not really understanding why the change is needed but the chenges look fine.
CoPilot suggestions seem reasonable to be, up to you.
|
Thanks, comments fixed. Will squash submit. |
Lint error, should probable be updated
|
will fix in separate PR |
it seems like there is some sort of life-cycle problem, honestly not 100% sure what, but this fixes the problem.