[TIMOB-27437] Android: Add @RequiresApi() annotations to core java code
GitHub Issue | n/a |
---|---|
Type | Improvement |
Priority | Low |
Status | Open |
Resolution | Unresolved |
Affected Version/s | n/a |
Fix Version/s | n/a |
Components | Android |
Labels | android, annotations, java |
Reporter | Joshua Quick |
Assignee | Joshua Quick |
Created | 2019-10-02T18:57:52.000+0000 |
Updated | 2021-02-22T19:06:11.000+0000 |
Description
*Summary:*
Google supports Java annotation
@RequiresApi(number)
which can be applied to classes, methods, member variables, etc. This can be used to trigger linting errors/warnings if an API was accessed on an API Level older than what was set in the annotation.
https://developer.android.com/reference/android/support/annotation/RequiresApi
We should leverage this feature throughout our core Titanium code to help minimize mistakes and ensure we're checking the currently running API Level before making high API Level call. This will help avoid crashes when on older Android OS versions.
*Example:*
The below screenshot shows this in action. A @RequiresApi(20)
annotation is applied to method onApplyWindowInsets()
. In the method below, we call the onApplyWindowInsets()
method twice. One call is unguarded and the other call is within an if-check block which checks if we're running in API Level 20 or higher. The linting tool correctly shows a red underline for the unguarded method call. This is what we want.
!RequireApiLinting.png|thumbnail!
*Notes:*
We should do this after switching our build system to gradle. This is because the gradle linting tool performs the API Level checks.
Attachments
File | Date | Size |
---|---|---|
RequireApiLinting.png | 2019-10-02T18:39:09.000+0000 | 438741 |
No comments