5

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

Eren Utku
  • 1,731
  • 1
  • 18
  • 27
  • That looks absolutely right to me. The imported class `R` contains all the generated Ids for strings, drawables, viewIds etc. So it must be imported for java to use – JDurstberger Dec 01 '16 at 09:23
  • 2
    Of course, you are right. It is not a bug. But I do not want Android Studio to add random resources automatically. – Eren Utku Dec 01 '16 at 11:49

1 Answers1

7

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

Aydinozkan
  • 2,508
  • 2
  • 21
  • 26