Imports on the fly is adding random Resources and Static ID

426 Views Asked by At

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

1

There are 1 best solutions below

0
Aydinozkan On BEST ANSWER

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