Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Imports on the fly is adding random Resources and Static ID

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:enter image description here

like image 248
Eren Utku Avatar asked Dec 01 '16 09:12

Eren Utku


People also ask

How to fix imports in IntelliJ?

To optimize imports in a file, you can also press Ctrl+Alt+Shift+L , select Optimize imports, and click Run.

How do I stop auto import in IntelliJ?

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.

What is the shortcut for importing the methods?

You can simply import all of them by pressing the ALT + ENTER key.

How do I organize imports in IntelliJ?

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.


1 Answers

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

like image 157
Aydinozkan Avatar answered Sep 21 '22 03:09

Aydinozkan