I am using Android Studio 2.2.2; and "Optimize imports on the fly" option is checked.
The problem is, when I'm using a resource without its package; for example sampleString
instead of R.string.sampleString
Android Studio adds the below import
import static com.a.b.R.string.sampleString;
This problem also occurs when I create a new activity, Android Studio imports some random resource to the new created class.
import static com.a.b.randompackage.R;
I can fix this problem by unchecking "Optimize imports on the fly" but I want to keep it checked. Is there any other solution to remove these annoying imports?
Thank you.
My Auto Import Settings:
To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.
You can disable auto-import on completion and use quick-fixes instead: In the Settings/Preferences dialog ( Ctrl+Alt+S ), go to Editor | General | Auto Import. On the Auto Import page that opens, use the checkboxes in the TypeScript/JavaScript area to enable or disable import generation on code completion.
You can simply import all of them by pressing the ALT + ENTER key.
In Eclipse, you press CTRL + SHIFT + O “Organize Imports” to import packages automatically. For IntelliJ IDEA, if you press CTRL + ALT + O “Optimize Imports”, it just removes some unused imports, never imports any package.
Keep "Optimize imports on the fly" option checked.
Unchecking "Show import suggestions for static methods and fields" should do the trick:
Preferences -> Editor -> General -> Auto Import -> Show import suggestions for static methods and fields
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With