-
Notifications
You must be signed in to change notification settings - Fork 1
AndrDebug
If you are programming in C++ in android and you want to print something for example to check the value of a variable then all you have to do is: Include the AndrDebug.h (cbox/android_wiselib/androidConcepts/debugConcept/AndrDebug.h). If you copy that file to your working directory you have to copy also javaEssentials.h/.cpp files because these files are needed by JNI.
For example, lets say that you have declared an integer variable myVar and you want to check its value. In a classic unix/linux programming, printing the value of the variable in the command line would be enough but while being in native code, no command line exists(actually there is but you can't see it).The only thing you can do it to print it somewhere in the application and this is the usage of debug class. Let's see below how debug concept can be used in android:
... int myVar; ... //some operations here with myVar //declaring an AndrDebug class AndrDebug myDebug; //printing just like it was a printf function testDebug.debug("myVar value: %d\n", myVar); ...
This code will create an alarm dialog in the application which will contain the string that is created by the debug method.
Due to inconsistencies of JNI with the android SDK, you have to include this method in your application you are developing so that C++ code can access it through JNI.
public void debugFromNative(String s) { // prepare the alert box AlertDialog.Builder alertbox = new AlertDialog.Builder(this); // set the message to display alertbox.setMessage(s); // add a neutral button to the alert box and assign a click listener alertbox.setNeutralButton("Ok", new DialogInterface.OnClickListener() { // click listener on the alert box public void onClick(DialogInterface arg0, int arg1) { // the button was clicked // do nothing } }); // show it alertbox.show(); }