Android Question Problem with LogCatData event

Discussion in 'Android Questions' started by mauro vicamini, Mar 27, 2015.

  1. mauro vicamini

    mauro vicamini Active Member Licensed User

    Hi Everyone,
    I've a problem with LogCat event.
    I start the logcat using

    objLog.LogCatStart(Args, "objLog")
    then in the objLog_LogCatData I would catch the logdata

    Sub objLog_LogCatData (Buffer() As Byte, Length As Int)
    Dim data As String
       data = 
    End Sub
    But when i start LogCatStart, I get the following error

    Ignoring event: objlog_logcatdata. Raised from the wrong thread.

    The goal for me is to log the errors raised from a Javascript console.log command in a webview, but when the javascript console.log is fired I get the above error even if I read the console.log string on the IDE Log window (so that mean that the setup of webchromeclient and webviewextra stuff is correct).

    I've read in a post in the forum that the logcat event runs in a different thread, and that the solution is to use the Threading Library and that is needed to only declare and initialized a thread object to making it work. I've done that but the problem still remain .

    Pls, someone could post an example on how to catch data from the LogCatData events correctly?

    Many thanks.
  2. Erel

    Erel Administrator Staff Member Licensed User

    Which version of B4A are you using?

    Test it in release mode.
  3. mauro vicamini

    mauro vicamini Active Member Licensed User

    Hi Erel!
    Thanks for your replay.
    I'm using B4A 3.0.
    I've tested a little application that write on a file the data arriving from logcat it in Relese mode and seems to work( i say "seems" because I catch a lot of messages but not the one related of my application, maybe I've not cathed for enough time).
    But in this little application I've don't used the threading library. Is It needed or not?
    I see that in the logcat data arrive a lot of messages not related to the application: is it possible to filter the messages capturing only messages related to the application?
    For clearing any doubts could you pls post a little example with the correct use of logcat library?
    If it could be usefull I post my one:
    Sub Process_Globals
    'These global variables will be declared once when the application starts.
        'These variables can be accessed from all modules.

    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.
        Dim objLog As LogCat
    Dim Args(1As String
    Dim Button1 As Button
    Dim Button2 As Button
    Dim Button3 As Button
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    End Sub

    Sub Activity_Resume

    End Sub

    Sub Activity_Pause (UserClosed As Boolean)

    End Sub
    Sub objLog_LogCatData (Buffer() As Byte, Length As Int)
    Dim data As String
       data = 
    "data", data,File.DirRootExternal,"logcatxxx.ini")

    End Sub
    Sub WriteIni(mykey As String,myvalue As String,fPath As String,filename As String)
    Dim Map1 As Map
    If File.Exists(fPath,filename) Then
    File.WriteMap(fPath, filename, Map1)   'to create it if not exist
       End If
       Map1 = 
                Map1.Put(mykey, myvalue)
    File.WriteMap(fPath, filename, Map1)
    End Sub

    Sub Button1_Click
    End Sub
    Sub Button2_Click
    End Sub
    Sub Button3_Click
    End Sub
    Another question : Javascrit messages sent with console.log from a webview are marked with the same ID of the application that contains the webview?

    Thanks a lot again for your replay.
  4. Erel

    Erel Administrator Staff Member Licensed User

    You don't need to use the Threading library. Just make sure to remember that unlike all other events in B4A, this event is raised on a different thread.

    Your code is very inefficient. You should use an TextWriter to append the data to an already open file and call flush from time to time.

    LogCat will only capture messages from your app on Android 4.1+.
    The optional arguments are documented here:
    mauro vicamini likes this.
  5. mauro vicamini

    mauro vicamini Active Member Licensed User

    Thanks a lot Erel.
    I know that my code is inefficent but was only a quick example to see if I could catch the messages from logcat. I will consider your advice.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice