On-the-fly imports add random resources and a static identifier

I am using Android Studio 2.2.2; and "Optimize imports on the fly . "

The problem is that I am using the resource without its package; e.g. sampleString instead of R.string.sampleString

Android Studio adds below import

 import static com.abRstring.sampleString; 

This problem also occurs when creating a new action, Android Studio imports some random resource into a new created class.

 import static com.abrandompackage.R; 

I can solve this problem by unchecking the " Optimize imports on the fly " box, but I want it to be checked. Is there any other solution to remove these annoying imported goods?

Thanks.

My auto import options: enter image description here

+5
source share
1 answer

Check the box next to "Optimize imports on the fly."

Uncheck "Show import suggestions for static methods and fields" to do the trick:

Preferences -> Editor -> General -> Auto Import -> Show import suggestions for static methods and fields

+6
source

Source: https://habr.com/ru/post/1260632/


All Articles