简体   繁体   中英

Android Studio Structure tool

I cant find info on this anywhere. I am wondering about the significance of Structure tool in Android Studio. It shows me the class structure with all the methods. Is it showing me in what order the methods will get called when the code runs or are they sorted in some other way?

Is there a way to see in what order the methods will get called apart from setting breakpoints?

在此处输入图片说明

If you hover over the icons on the toolbar, you'll know what it does. It does not sort in the order of it being called.

  • The first icon sorts it according to the visibility of the methods, ie public, protected and then private.
  • The second one sorts it by name.
  • Rest of them are what contents of the file you want to show, ie show variables, anonymous inner classes, etc
  • It also gives you the option to expand and collapse methods and scroll to, from source.

It's basically a tool to help developers understand the structure of the file. It gives an overview of the methods at a glance for easy readablility.

Android Studio Structure工具顺序

InnerClass -> Interface -> Method -> Field

You are looking for sequence diagrams . The Android Studio does not provide such tool, but there are external ones (eg Visual Paradigm ) that can generate sequence diagrams from Java code, so you can see the execution order of methods.

By the way, the ordering you see in the Structure panel can order the fields / methods in multiple ways (you can even combine them):

  • by visibility : this is the leftmost icon with the down arrow next to the green and red locks; it sorts the items by their visibility in the following order: public first, then protected, package private, and private
  • alphabetically : the second icon from the left with the down arrow next to an a and z characters
  • default : shows the items in the same order as they appear in your class

Worth mentioning that methods appear before fields no matter what.

Note that what you're doing is reverse engineering, which is usually bad practice. A proper way would be that you first plan your class (and application) using class and sequence diagrams among others, then implement the solution.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM