CodeName OneShai Almog4 min readintermediate
Watch Apps: One Codebase, Two Real Applications
Summary
Codename One now lets you build an Apple Watch or Wear OS companion app from a single codebase by specifying a watchMain class and optional watchStandalone flag. The new WearableConnection API offers putData, sendMessage, and transferFile primitives for asynchronous phone‑watch communication, with simulator support for both platforms.
- Set codename1.watchMain to the watch entry class; use codename1.watchStandalone=true to produce a standalone Wear OS APK.
- Use WearableConnection.putData for convergent state, sendMessage for immediate request/reply with replyFailed handling, and transferFile for large payloads.
- Phone and watch share Java source, resources, CSS, and themes but have independent Storage, Preferences, and SQLite files.
- Simulator launches both processes; CN.isWatch() and the watch theme let you adapt UI without code duplication.
Mobile developers building cross‑platform apps can reuse a single codebase for phone and watch companions while handling asynchronous communication reliably.
6/10