How can i find where a method or a variable is used in Android Studio (shortcut)

35,292

Solution 1

In Android Studio, highlight the method and either right click > Find usages or use the Alt+F7 shortcut.

Edit: Ctrl+left click on a method is useful for finding where that method was initially declared

Solution 2

For Ubuntu users:

For me Alt+F7 has not worked, so I've solved the conflict by going to the

Ubuntu System settings-> keyboard -> shortcuts

and changing Alt+F7 in there with another combination.

And now it's working ))

Solution 3

Just click on the method or variable and any usages will be highlighted and on the scroll bar on the right side of your code you will see gray bars appear, those are the usages of the current highlighted (or clicked on) variable or method within your code.

Solution 4

Here are different key shortcuts for displaying method or variable usage. The keymaps with F14 in them were added by me; the others are default. For Windows (and Linux?), replace the key with Ctrl (I think). Find Usages shows them in a dedicated window in Android Studio (the solution in other answers), while Show Usages puts them in a popup (second image below).

My Android Studio preferences

Usage popup (<kbd>⌘</kbd><kbd>option</kbd><kbd>F7</kbd>

Solution 5

To find all uses of a variable or method in Android Studio you can use

  1. ctrl+shift+F7(window/Ubuntu)
  2. after that for navigation purpose you can use F3
Share:
35,292
Omar BISTAMI
Author by

Omar BISTAMI

Linked in : ma.linkedin.com/in/omarbistami/fr

Updated on December 18, 2020

Comments

  • Omar BISTAMI
    Omar BISTAMI over 3 years

    I know how to find the source by using ctrl + left click on a method, for example, but what if I want to find where this method is used? I'm using Windows 7.

    Let's suppose I have the following method:

    class A {
        public int sum(int a, int b) {
            return a+b;
        }
    }
    

    and I am using this method in

    class B {
        ...
        a.sum(c, d);
        ...
    }
    

    and I want to find where I used sum while I was in class A.

    PS: I'm new to Android studio (started using it about a month ago).