Friday, October 14, 2016

How to debug android application tutorial

Debugging is needed by programmer in order to understand what makes an app crashes or why the app behaves unexpectedly. Using Android Studio, every programmer able to debug their code easily.

Below are the steps to debug android code with Android Studio :

1.  Put breakpoint (small red circle)  at the line of code where you want to debug or investigate by clicking at the right of line number. in the example, I put breakpoint at line 22. see the picture below :

Put breakpoint at line of code that you want to debug.
2. Run application in debug mode by clicking debug button at Android Studio Menu bar at the top.

3. after app successfully installed, Just play with your app that will execute the line of code that has the breakpoint. In the example, I should click login button to execute the line of code that has breakpoint.

4. When the app run and want to execute the code at the breakpoint, it will stop before executing that line (line 22).  Click step over like in the picture below to execute that line of code or press F8.

App will stop execute at breakpoint line.
5. When you click step over or F8 the app  execute line 22 and you can investigate variabel intent to know its value by pointing cursor arrow at that variable. You can also investigate parameter View v
that is supplied by onClick method to know its value by pointing cursor arrow at v variable.
The purpose of debugging is to make sure that that line of code contains the right values that you expected. for example if v or intent is null, but you expected not null then that is the problem of error and you need to solve exactly at that line.

6. When you are done investigating the line at the breakpoint, you can resume executing the app by pressing the resume button at the top left of debug console (green triangle button).


Thank you for visiting our website. Just comment below if you have any question.




No comments:

Post a Comment