How to auto import the necessary classes in Android Studio with shortcut?

Solution 1:

Go to File -> Settings -> Editor -> Auto Import -> Java and make the below things:

Select Insert imports on paste value to All

Do tick mark on Add unambigious imports on the fly option and "Optimize imports on the fly*

Screenshot

Solution 2:

Go on the missing declaration with cursor and press alt+enter enter image description here