Skip to content

Latest commit

 

History

History
17 lines (17 loc) · 3.85 KB

android-dev-notes.md

File metadata and controls

17 lines (17 loc) · 3.85 KB

Android development notes

  • The auto-size countdown text can jump upwards when the text changes or the soft keyboard opens on Android SDK 30 - 32. On earlier versions of Android, auto-text resizing doesn't always grow back when the text shrinks. The workaround is to set the height to 0dp (called MATCH_CONSTRAINT in the docs) instead of wrap_content + app:layout_constrainedHeight="true".
  • Android 12 on Pixel 3 (at least) drops the initial "off" period from the notification vibration pattern, which makes it impossible to sync the notification's vibration pattern to its sound. Work around that by adding a tiny pulse at the start.
  • To avoid flakiness, Espresso Instrumentation tests sometimes need delays or additional actions, in addition to turning off Android animations. Is there a better way?
  • To get good contrast in notification text on Android SDK 24 - 26, use different day and night color resources. On Android SDK 23, color the mid-gray background area to get contrast with both the medium gray heads-up notification text and the light white pull-down notification text. The color setting carries over from a notification to its replacement so there's no way to consistently set different background colors for the two cases.
  • The EditText and Material Design TextInputEditText widgets don't call their OnFocusChangeListener. Work around that with a subclass of TextInputEditText that overrides onFocusChanged() to call its own listener.
  • Automatic focus in the text field on Activity start, app switch, or rotation is distracting and annoying, esp. with its CLEAR_TEXT (X) endIcon. So force it to defocus and reset its contents. Hiding the soft keyboard seems to be an unsolved problem in general.
  • On SDK 27, double-clicking the EditText field would cause log errors FileNotFoundException: No file for null locale and TextClassifierImpl: Error getting assist info. On SDK > 27, something calls the TextClassifier on the UI thread, logging TextClassifier called on main thread because it can be slow. To avoid the delay and potential ANR, switch to the no-op TextClassifier.
  • Making the home screen widget responsive to its size and screen orientation varies by Android SDK version. Android 12+ supports view mappings to switch between layouts without waking the app. View mappings and layout managers react to actual sizes. For Android < 12, use the onAppWidgetOptionsChanged() hook to respond when the user resizes a widget. It only receives the size range minWidth x maxHeight on portrait to maxWidth x minHeight on landscape, and it rarely gets called when the screen rotates, so it can only set a layout for the size range. Any finer responsiveness must be implemented by the layout managers and density/size/orientation-specific resources.
  • Android's Split Screen feature can crash or refuse to split the screen, depending on the app's minHeight value, at least on SDK 29+. Tune the minHeight value experimentally.
  • On SDK < 23, an icon in the home screen widget's background gets stretched horizontally. The workaround is to skip the icon on those Android versions.
  • Show a large notification icon in API < 24 so Android won't stretch the small icon to a fuzzy large icon. Otherwise large icons are supposed to be reserved for cases like a user photo.
  • When paused, a Chronometer view can’t show the right time value because its API doesn’t handle that case. A Chronometer also ignores its format string when stopped. The workaround is to switch to a Text view when paused. This app uses Chronometers in home screen widgets and notifications.
  • Formatting the elapsed time like 0:12 would look nicer than 00:12 but the latter matches Android’s Chronometer view for consistency.
  • The widget’s ViewFlipper must explicitly set android:measureAllChildren="false", otherwise flipping its subviews will resize the adjacent ImageButton on Galaxy Nexus Jelly Bean.