简体   繁体   中英

how to figure out the flow of an android project using debug

I'm new to android development. I download a toy project and want to figure out the flow of this project. Can I use debugging to figure out it and how?

Let me explain it more detail. Every android project starts from an "main" activity. I guess I find the "main" activity for the project and set a breakpoint at the onCreate method of this "main" activity. I expect to run this project from that breakpoint one step by step to figure out the flow. However it doesn't work since the debugging stop after finishing the onCreate method.

The "flow" of an android application is more like an asynchronous model than a sequential flow of action. There is a main application loop that processes external events (such as clicks on button) and callbacks related to the activity lifecycle (such as your onCreate method), and lot of other stuff.

Every event is put into the queue and processed asynchronously, so it's not easy to follow it. It's better to think about actions and reactions. In any case you can dig into the android source code and see what's running behind the scenes. Some hints about the model of android apps can be found here but any google search for "android ui thread queue" would lead to relevant info.

Start with AndroidManifest.xml file. Open it and look for an Activity with LAUNCHER category. Then open that Activity and go to onCreate(...) method. This is where your app starts. Inside the method, there is a call to setContentView(R.layout.some_layout). some_layout.xml in res/layout folder is UI for this Activity.

Each window you see in Android app is an Activity and each Activity has a layout file.

If you want to learn the flow of a typical android application, I would recommend you download the samples if you haven't already and add your own log statements. You could use the debugger too. Then start making small changes here and there to force different 'flows' of control, as you make guesses about what should happen and observe your logging statements and the app behavior to see what's going on.

The sample projects can be downloaded from the adt plugin in eclipse and come as ready-made projects. They are also a good way to learn because they are generally the 'best-practice' way of doing things.

Hope that helps! Good luck :)

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