Android Question NB6 and Android 6.x crashing

ac9ts

Active Member
Licensed User
Longtime User
I'm using NB6 for notification for a service. I'm getting a relatively large number of reports of the following, all from Galaxy devices running Android 6.0:

B4X:
android.app.RemoteServiceException:
at android.app.ActivityThread$H.handleMessage (ActivityThread.java:2019)
at android.os.Handler.dispatchMessage (Handler.java:102)
at android.os.Looper.loop (Looper.java:158)
at android.app.ActivityThread.main (ActivityThread.java:7225)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)

I did a little investigation and noticed NB6 requires a 24x24 icon. I used a 72x72 icon and loaded it with LoadBitmapResize to 24Dip x24Dip initially. Thinking the DIP unit was actually making the icon larger than 24x24 pixels, I then re-sized the icon to 24x24 and used LoadBitmap. Both still cause the error.

This is the code I'm using to keep the service running and the notification.

B4X:
Sub Service_Start (StartingIntent As Intent)

    GetLocks

    Service.StartForeground(nid, Create_Notification(Common.AppName, Common.AppVer))
 
End Sub


Private Sub GetLocks
 
    LogColor("Getting Locks", Colors.Green)
 
    Try
        Dim r As Reflector
        r.Target = wifilock
        r.RunMethod("acquire")
    Catch
        LogColor("Aquire WiFiLock Failed!", Colors.Red)
    End Try
 
    Try
        Awake.PartialLock
    Catch
        LogColor("Aquire PartialLock Failed!", Colors.Red)
    End Try

End Sub

Private Sub Create_Notification(L1 As String, L2 As String) As Notification

    Dim BM As Bitmap = LoadBitmap(File.DirAssets, "icon_sm.png")
 
    Dim Target As Object
    If Main.Tablet Then
        Target=GUI_T
    Else
        Target=GUI
    End If
 
    Dim n As NB6
    n.Initialize("default", Common.AppName, "LOW").AutoCancel(False).SmallIcon(BM)
    n.SetDefaults(False, False, False)        ' Turn off sound, light, and vibrate
 
    Dim Noti As Notification = n.Build(L1, L2, "tag1", Target)

    Return Noti
 
End Sub

My Galaxy S4 running 6.0 doesn't exhibit this error but it is running a custom ROM so maybe it's a Samsung OS tweak that's causing it?
 
Last edited:

ac9ts

Active Member
Licensed User
Longtime User
Additional info.

One user is reporting that the initial notification works correctly as described above. What is happening, it seems, is the crash occurs when I attempt to modify what the notification says.

It is used in a streaming audio app. The notification changes to the stream title. "nid" is the same as above, 1.

B4X:
    Dim n As Notification = Create_Notification(F.Title, F.Series)
    n.Notify(nid)

I used the code in Background Location Tracking tutorial (https://www.b4x.com/android/forum/threads/background-location-tracking.99873/) as an example.

Added: My simple fix is to not do the title updates on Android 6 devices. This prevents the crashes but I'd still like to find out why so I can fix it and put that functionality back.

B4X:
If SDK<>23 Then
    Dim n As Notification = Create_Notification(F.Title, F.Series)
    n.Notify(nid)
End If
 
Last edited:
Upvote 0

ac9ts

Active Member
Licensed User
Longtime User
You can try to cancel the previous notification before you show the new one:
B4X:
Dim n As Notification = Create_Notification(F.Title, F.Series)
n.Cancel(nid)
Sleep(100)
n.Notify(nid)

That's something to keep in mind but, until I get a device in my hands that exhibits the problem, I'll stick with just not doing the update on 6.x devices. It won't affect too many users and it was a new feature anyway so they won't miss it.
 
Upvote 0

Similar Threads

Top