Android Question anr error starting from android 6.0

Tempomaster

Active Member
Licensed User
Longtime User
Hello,

I've had a problem with an anr problem for some time. I can not solve it on my own. This problem only occurs from Android 6.0 . Until Android 5 there are no problems. it would really help if i could get a tip. I send in the plant the ANR log file and the affected java file.

The header for the error means:

executing service gd.tempomaster_pro/.svcoverlayinfo

In the log file is at the bottom:

- waiting to lock an unknown object ? Obviously something is missing.

Best regards,
Gunnar Daehling
 

Attachments

  • anr.log.txt
    9.7 KB · Views: 899
  • svcoverlayinfo.java.txt
    287 KB · Views: 355

Tempomaster

Active Member
Licensed User
Longtime User
That's a problem. I need an alternative. Otherwise, the main advantage of my app is no longer available.

I have another thought. I update the properties of the window's objects (panels, labels) with parallel threads. The position data is accessed primarily by the touch / move event of the window library. however, I also allow updating through a timer-controlled routine. An update from the event "GPS_LocationChanged" is also ongoing.

Could it help prevent concurrent access to the window from different threads? I have also checked again and found that I have also enabled on methods of the window parallel access. A parallel access is a random event. Maybe that explains why the app sometimes lasts longer with no error for some users.
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
partly timer controlled,
partly gps controlled,
AsyncCallSub from the "CallSubExtended" library of Informatix to load the data in the background

I looked again at the examples of the overlay library of informatix. He only updates the window via the timer-controlled thread. I will rebuild my app so that the treads only writes the values into global variables. The timer thread accesses these variables and updates the overlay window as the only thread. The parallel access to global variables should be able to separate android cleanly. I read that at least. Is this way thought right?
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
I recommend you to get an Android 6+ device.

There remains only the purchase of a new device. Only later will come android 9, 10, etc. I feel a little like Microsoft Windows. Programs have quit their service with each new version. In the search for a useful emulator, I've lost my teeth.
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
Erel, I'm very grateful for your advice. Asynchronous access to the database works very well. I will continue to test and report on my findings. On Google Play, my average score is still 4.5 stars. It is also difficult to estimate how much this ANR problem can be felt by the customer. There are also some errors that the user does not notice because they do not interfere with the app's workflow. Only advises google these errors necessarily to go.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
I'm not familiar with the overlay library.

I can say that you should avoid using additional threads in your code unless you don't have a choice. If you are reading the data from a database then you should use the async methods instead.
CallSubExtended uses BA.SubmitRunnable to parallelize execution. It is very unlikely that the use of this library ends with an ANR. One of its goals is to avoid them.
Without the code and without being able to reproduce the case, it's almost impossible to offer solutions.
 
Upvote 0

Informatix

Expert
Licensed User
Longtime User
There remains only the purchase of a new device. Only later will come android 9, 10, etc. I feel a little like Microsoft Windows. Programs have quit their service with each new version. In the search for a useful emulator, I've lost my teeth.
Download the Genymotion emulator. It simulates very closely different devices (including their bugs) and Android API. Apart from very specific cases, GM is a reliable tool.
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
I don't think there's a relationship between the error and the OverlayWindow library.

I can not imagine it either. I now have evidence that it could have something to do with the startup behavior of the Gps. I have to test the "GPS_LocationChanged" replaced. I have written a subroutine with which I emulate the Gps. I have saved the coordinates of a car ride in a GPX. I have this controlled by a timer in the app transferred. In the simulation, there was a problem switching from no Gps to existing Gps. By changing the code I got the app now on the emulator integrated in b4a (android 7.0) to run without errors.

Thank you for your hints to the emulator and the hint to your library CallSubExtended.

Best regards,
Gunnar
 
Upvote 0

Tempomaster

Active Member
Licensed User
Longtime User
Hello,

the problem is solved. For all interested I explain briefly how the problem was managed from the world. I use the example of the library overlay window (author Frédéric Leneuf-Magaud / Informatix).

The activity from which the service is called for the overlay window:
B4X:
Sub Process_Globals
   Dim homeapp As Intent
   .
   .
End Sub

Sub Activity_Resume
    'Opens the overlay window
    CallSubDelayed(SvcOverlayInfo, "ShowWindow")

  ' Home-Key after start overlay window
 
   homeapp.Initialize(homeapp.ACTION_MAIN, "")
   homeapp.AddCategory("android.intent.category.HOME")
   homeapp.Flags = 0x10000000

   ' StartActivity(homeapp)
End Sub

The Service:
B4X:
#Region  Service Attributes
    #StartAtBoot: False
#End Region

Sub Process_Globals
    Dim OW As OverlayWindow
    Dim MaxWidth As Int
    Dim InitialPosX, InitialPosY As Int
    Dim Timer_Svc As Timer
    Dim C As Cache
    Dim SB As StringBuilder
End Sub

Sub Service_Create
End Sub

Sub Service_Start (StartingIntent As Intent)
    Service.StartForeground(1, CreateNotification("Tempomaster Setup","","icon60",Main,False,False))

    'The timer is used to refresh the information every second
    Timer_Svc.Initialize("TimerSvc", 1000)
End Sub

Sub Service_Destroy
    'Stops the timer
    Timer_Svc.Enabled = False

    'Closes the window
    If OW.IsInitialized Then
        OW.Close
    End If
End Sub

Sub InitWindow
    'Creates the overlay window
    MaxWidth = GetDeviceLayoutValues.Width
    OW.Initialize2(10dip, 10dip, MaxWidth / 2, 60dip, "Pnl")
    Dim Pnl As Panel = OW.Panel
    Pnl.Color = Colors.ARGB(160, 50, 50, 50)

    'Creates the window layout (two labels and two panels)
    Dim lblDateTime As Label
    lblDateTime.Initialize("")
    lblDateTime.TextColor = Colors.White
    Pnl.AddView(lblDateTime, 0, 0, -1, 20dip)

    Dim lblFreeMem As Label
    lblFreeMem.Initialize("")
    lblFreeMem.TextColor = Colors.White
    Pnl.AddView(lblFreeMem, 0, 20dip, -1, 20dip)

    Dim pnlBackground As Panel
    pnlBackground.Initialize("")
    pnlBackground.Color = Colors.Green
    Pnl.AddView(pnlBackground, 0, 47dip, -1, 13dip)

    Dim pnlProgression As Panel
    pnlProgression.Initialize("")
    pnlProgression.Color = Colors.Red
    Pnl.AddView(pnlProgression, 0, 47dip, 50dip, 13dip)

    'Initializes the information (date/time and free memory)
    Dim Ticks As Long = DateTime.Now
    lblDateTime.Text = DateTime.Date(Ticks) & "  " & DateTime.Time(Ticks)
    SB.Initialize
    SB.Append("Free mem: ").Append(Round(C.FreeMemory / 1024)).Append(" Kb")
    lblFreeMem.Text = SB.ToString
    pnlProgression.Width = (MaxWidth / 2) * (1 - (C.FreeMemory / C.MaxMemory))
End Sub

Sub ShowWindow
    If Not(OW.IsInitialized) Then
        InitWindow
    End If
    If Not(OW.IsOpen) Then
        OW.Open
    End If
    OW.Visible = True

   ' *************************
    StartActivity(main.homeapp)
    Timer_Svc.Enabled = True

   ' *************************
End Sub

Sub TimerSvc_Tick
    'Refreshes the date and time
    Dim Ticks As Long = DateTime.Now
    Dim lblDateTime As Label = OW.Panel.GetView(0)
'    lblDateTime.Text = DateTime.Date(Ticks) & "  " & DateTime.Time(Ticks)

    'Refreshes the free memory amount
    Dim lblFreeMem As Label = OW.Panel.GetView(1)
    SB.Initialize
    SB.Append("Free mem: ").Append(Round(C.FreeMemory / 1024)).Append(" Kb")
    lblFreeMem.Text = SB.ToString
    Dim pnlProgression As Panel = OW.Panel.GetView(3)
    Dim NewWidth As Int = (MaxWidth / 2) * (1 - (C.FreeMemory / C.MaxMemory))
    If pnlProgression.Width <> NewWidth Then
        pnlProgression.Width = NewWidth
    End If

    'Ensures that the window is visible
    ShowWindow
End Sub

The text after "Home-Key after start overlay window" in the activity works fine until Android 5.0. As of Android 6.0, it leads to the usability of the app by ANR error. The overlay window will open for a while and then close automatically. However, this error does not always occur. Many users reported that they could sometimes use the app.

In order to get the app completely error free, the code for the start the home activity in the activity was commented. The home activity call started now after the complete overlay window was drawn (Sub InitWindow). I marked this call with ****** in the code.

The ANR errors were finally triggered on the first access to the overlay window. This was simply not yet properly initialized (although it has already been shown). The search has cost me many hours of work and nerves. Thank you all for your hints. Especially Erel has taken a lot of time. Thanks a lot.

Best regards,
Gunnar
 
Last edited:
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…