How to find the code related to a small UI component quickly in a large Android codebase?

StackOverflow https://stackoverflow.com/questions/11962067

  •  26-06-2021
  •  | 
  •  

Pergunta

I just started my work as an Android developer. My first assignment is to fix several bugs of an App call DailyFinance.

One bug is UI related, if you click a button on a certain page, a dialog will pop up, but the dialog is not displayed properly. My question is how can I locate the code (xml layout file as well as activities) related to the dialog quickly in the codebase which I am not familiar with?

Foi útil?

Solução

Couple approaches come in mind:

  1. Search for any text that displayed on the target dialog.
  2. Search button text and locate the xml layout file that that contains the button which launch the target dialog
  3. Once find the xml layout file, determine the button 'id' as xxxxx, then you can further search for source contains references to 'R.id.xxxxx'

Outras dicas

Set breakpoints on methods in files that implement the dialog. So maybe search for dialog and then put breakpoints inside the dialog. See it it gets hit when your dialog gets pulled up. Or just see where the layouts are set in files that have the word dialog in them. look for R.layout.someLayoutName.

One other suggestion is for some difficult layouts where its tough to see whats going on you can use the HierachyViewer to see the runtime view layouts: http://developer.android.com/tools/help/hierarchy-viewer.html Its worth running on your app to see the structure of the layouts at runtime which is often hard to see these relationships in the layout files before they have been inflated.

BTW, I was a student of CS and the biggest mistake I ever made was not to learn the debugger inside and out. Its without a doubt the most powerful ally you have to learn as well as fix bugs. If you think about it, code really is only an abstraction until you see it running inside the debugger.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top