Java Question Wrapper for AppBugTracker android library

frapel

Active Member
Licensed User
Longtime User
I am trying to create a wrapper to the AppBugTracker android library (www.appbugtracker.com) to install an UncaughtExceptionHandler different from the B4A default.

Wrapping the library is not a problem, but after calling the init method of library (that changes the default UncaughtExceptionHandler) this seems not changed or changed again to default handler.

My wrapper create a simple Initialize method that do this:

B4X:
public static void Initialize(BA ba, String appToken) {

        Context context = BA.applicationContext;
        Logger.setLevel(LoggerLevel.TRACE);

        Log.d("appbugtracker", "before init: " + Thread.getDefaultUncaughtExceptionHandler().getClass().getName());

        com.appbugtracker.AppBugTracker.init(context, appToken);

        Log.d("appbugtracker", "after init: " + Thread.getDefaultUncaughtExceptionHandler().getClass().getName());
    }

before the AppBugTracker.init the value of UncaughtExceptionHandler was anywheresoftware.b4a.BA$1
and after the init call the method value is changed to com.appbugtracker.impl.AbtImplIncidentHandler

I call my Initialize method in Activity_Create method of my B4A application:

B4X:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Dim abt As AppBugTracker
    Dim abtToken As String = “—token-here—“
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
'    If FirstTime Then
        abt.Initialize(abtToken)
        Msgbox("richiamato AppBugTracker.Initialize", "DEBUG")
'    End If
 
    Dim b As Button
    b.Initialize("b")
    b.Text = "Raise Exception"
 
    Activity.AddView(b, 0, 100%y - 50dip, 100%x, 40dip)
End Sub

Sub b_Click
    Dim s() As String
‘  // Raise an exception here, that should use the AppBugTracker handler
    If s(0) = "a" Then ToastMessageShow(“throws exception”, False) Else ToastMessageShow(“ok”, False)
End Sub

But when I click on the button trying to raise an exception the default handler (defined in BA static block) is used instead of com.appbugtracker.impl.AbtImplIncidentHandler as you can see in the attached screenshot.

I have also seen the thread related to ACRA :

http://www.b4x.com/android/forum/threads/trying-to-create-acra-library.19720/#post-113855

but i didn't understand how to override the exception handler.
 

Attachments

  • Screenshot_2014-07-19-14-22-17.png
    186.7 KB · Views: 222

warwound

Expert
Licensed User
Longtime User
Hi.

Debug it...
Add a new java method to your library:

B4X:
public static void LogIt(){
    Log.d("appbugtracker", "LogIt:  " + Thread.getDefaultUncaughtExceptionHandler().getClass().getName());
}

Now in your b4a code:

B4X:
Sub b_Click
    '    which handler is being used right now?
    apt.LogIt
    Dim s() As String
    If s(0) = "a" Then ToastMessageShow(“throws exception”, False) Else ToastMessageShow(“ok”, False)
End Sub

Do you see the b4a or appbugtracker handler logged?

Martin.
 

Roberto P.

Well-Known Member
Licensed User
Longtime User

hello
how and where you can create new methods in Java?
 

Roberto P.

Well-Known Member
Licensed User
Longtime User
thanks DonManfred
as I understand it, we can re-implement inline functions in the class? For example, I can reimplemtare functions of class "super" an activity?

I explain better what I'm trying to understand and do:
in B4A you can not create derived classes, so I'm trying to find a way to do it in Java and use objects in B4A. In particular, I need to create a class derived from Activity to use in B4A.

You can be done? There are examples that approach (which I did not find)?
thanks
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…