Android Studio Beta (0.8) has a nifty new feature where it checks that some int
parameters are not arbitrary integers, but rather have some properties.
All annotations, that you can use with android.support.annotation
you can find here.
And technical doc about supporting annotations.
Try this answer: Its working... Put this code into your build.gradle
android {
lintOptions {
disable "ResourceType"
}
}
(Thanks to @CommonsWare for the heads up).
There are Java annotations to support these checks in your own code. They can all be found in the android.support.annotations
package:
IdRes
DrawableRes
LayoutRes
StringRes
In this case, for example, I could use:
private void mySetContentView(@LayoutRes int resourceId) {
setContentView(resourceId);
}
and Android Studio will check that the provided resource id is indeed for a layout.
Moreover, these annotations are exported, so they can be especially useful when designing a library.
Sources:
This are all Annotations:
@AnimatorRes
@AnimRes
@AnyRes
@ArrayRes
@AttrRes
@BoolRes
@ColorRes
@DimenRes
@DrawableRes
@FractionRes
@IdRes
@IntDef
@IntegerRes
@InterpolatorRes
@LayoutRes
@MenuRes
@NonNull
@Nullable
@PluralsRes
@RawRes
@StringDef
@StringRes
@StyleableRes
@StyleRes
@XmlRes