Download the free trial version
Basic4android Video
Features
Tutorials and manuals
Showcase
Screenshots

Go Back   Android Development Forum - Basic4android > Basic4android > Basic4android Getting started & Tutorials
Documentation Wiki Register Members List B4P Search Today's Posts Mark Forums Read

Basic4android Getting started & Tutorials Android development starts here. Please do not post questions in this sub-forum.

Debugging android applications

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-08-2011, 09:23 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default Debugging android applications

This tutorial explains the new debugging features added in Basic4android v1.50 as well as the other related tools.
There is a new option under Project menu named Attach Debugger.



If this option is checked then the compiled code will contain debugging code.
The debugging code allows the IDE to connect to the program and inspect it while it runs.
When the program starts it will wait for up to 10 seconds for the IDE to connect. Usually the IDE will connect immediately. However if you run your program manually from the phone you will see it waiting.
The name of the compiled APK file will end with _DEBUG.apk. You should not distribute this apk file as it contains the debugging code which adds a significant overhead.

Another relevant option in this menu is Include Debug Information. This option doesn't have any effect when the Attach Debugger option is checked.
When Attach Debugger is not checked (which means that debugging code will not be added) this option determines whether the original B4A code will be added to the compiled APK file. Adding B4A code is useful for one specific reason. During an exception the message will include the original B4A line and not just the Java line.

When we run the program with Attach Debugger checked the IDE will open the debugger module at the bottom of the screen:



The debugging module contains three sections: subs stack, global variables and local variables. These sections show the data when the program is paused. Note that you can also see the variables data by hovering with the mouse over a variable name in the code.
Above the subs stack section there are useful buttons for continuing the execution, stepping to the next line, pausing execution and stopping the program. There is also an icon which tells us whether the debugger is connected. Double clicking on this icon will disconnect the debugger without killing the program.
Note that there is also a Debug menu which additionally includes Step Over (executes the next line without breaking on inner sub calls) and Step Out (gets out of the current sub and breaks) items.
The code editor is read only while the debugging module is visible.

Breakpoints - You can mark lines of codes as breakpoints. This is done by pressing on the grey area left of the line.
The program will pause when it reaches a breakpoint and will allow you to inspect the current state.

Logging - The Logs tab at the right pane is very useful. It shows messages related to the components life cycle and it can also show messages that are printed with the Log keyword. You should press on the Connect button to connect to the device logs. Note that there is a Filter checkbox. When it is checked you will only see messages related to your program. When it is unchecked you will see all the messages running in the system. If you are encountering an error and do not see any relevant message in the log, it is worth unchecking the filter option and looking for an error message.
Note that the log is maintained by the device. When you connect to a device you will also see previous messages.

Notes about the debugger:
- Breakpoints in the following subs will be ignored: Globals, Process_Globals and Activity_Pause.
- Services - Breakpoints that appear after a call to StartService will be ignored. Breakpoints set in Service_Create and Service_Start will pause the program for up to a specific time (about 12 seconds). This is to avoid the OS from killing the Service.
- Events that fire when the program is paused will be executed. Breakpoints in the event code will be ignored (only when the program is already paused).
- The data sent from the device to the IDE is limited in size. Long strings may be truncated.
Reply With Quote
  #2 (permalink)  
Old 02-09-2012, 09:33 AM
Newbie
 
Join Date: Feb 2012
Posts: 2
Default

Note that as of V1.80, you don't have the debug options in the Project menu.
You need to select 'Debug' mode in the dropdown that is in the middle of the top toolbar.
Reply With Quote
  #3 (permalink)  
Old 02-09-2012, 11:28 AM
Erel's Avatar
Administrator
 
Join Date: Apr 2007
Posts: 15,689
Awards Showcase
Basic4ppc Founder 
Total Awards: 1
Default

As noted above starting from v1.8 the menu options were removed.
Instead there is a new dropdown list:

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
debugging moster67 Basic4android Updates and Questions 1 11-04-2010 09:26 AM
Debugging suite for IDE, legacy and optimised applications agraham Additional Libraries 20 10-15-2010 09:38 PM
Include dlls and remote debugging Roadrunner Basic4ppc Wishlist 3 05-06-2009 07:01 AM
Distributing your applications Erel Code Samples & Tips 4 10-20-2007 06:41 AM
help plz with debugging this error.... Stellaferox Questions (Windows Mobile) 7 07-01-2007 02:39 PM


All times are GMT. The time now is 10:41 AM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0