Android Question objects and classes for notifications: I'm confused!

Roberto P.

Well-Known Member
Licensed User
Longtime User
after updating to version B4A 8.0 and then 8.3, notifications that used the Notification class no longer work.

I documented on the site, and I saw that I had to move the setInfo function to the end. In fact, with version 8.0 has started to work again, with version 8.30 it does not work anymore.

Here is the code:

Code: Copy
mNotification.Icon = "sync_gray_icon"
mNotification.Sound = False
mNotification.Vibrate = False
'06/11/2018 - with the new version the SetInfo must be called at the end of everything
'mNotification.SetInfo ("Sync notification", "Synchronization in progress .....", Null)

mNotification.Notify (mIDNotifyConnection)

First of all, I do not understand why the Error Notification class:

(RuntimeException) java.lang.RuntimeException: Can not change properties after call to SetInfo. Initialize the notification again.

Even if I set the SetInfo at the end ?!


Then I read these threads:

https://www.b4x.com/android/forum/threads/android-jar-targetsdkversion-minsdkversion.87610/#content

https://www.b4x.com/android/forum/threads/version-safe-notification.87663/

I saw example notifications with the class NB6 - Notifications Builder class (2018) that works well.

Before changing all the notifications of my application, I ask you for help to understand well, if I have to replace all Notification objects with the new class? Because?

Thanks in advance
 
Hi Erel,
this is the code

Code: Copy
    mNotification.Icon             = "sync_gray_icon"
    mNotification.Sound         = False
    mNotification.Vibrate        = False

    mNotification.SetInfo("Notifica Sync", "Sincronizzazione in corso.....", Null)
        
    mNotification.Notify(mIDNotifyConnection)

and this is the error:

java.lang.RuntimeException: Cannot change properties after call to SetInfo. Initialize the notification again.
at anywheresoftware.b4a.objects.NotificationWrapper.getND(NotificationWrapper.java:92)
at anywheresoftware.b4a.objects.NotificationWrapper.setIcon(NotificationWrapper.java:168)
at dev.meta.sb.csyncdispatcher._setnotification(csyncdispatcher.java:875)
at dev.meta.sb.csyncdispatcher._godispatcher(csyncdispatcher.java:493)
at dev.meta.sb.starter._godispatcher(starter.java:605)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1058)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1005)
at dev.meta.sb.csyncservice._startservicesoutput(csyncservice.java:1455)
at dev.meta.sb.csyncdispatcher._maintenance_output(csyncdispatcher.java:728)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1058)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1005)
at dev.meta.sb.csyncdispatcher._dispatchfunction(csyncdispatcher.java:384)
at dev.meta.sb.csyncdispatcher._godispatcher(csyncdispatcher.java:517)
at dev.meta.sb.csyncdispatcher._starterdispatcher(csyncdispatcher.java:946)
at dev.meta.sb.csyncdispatcher._startsync(csyncdispatcher.java:992)
at dev.meta.sb.starter._forcestartsync(starter.java:591)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.keywords.Common.CallSub4(Common.java:1058)
at anywheresoftware.b4a.keywords.Common.CallSubNew(Common.java:1005)
at dev.meta.sb.frmsync._cmdforcestartsync_click(frmsync.java:566)
at java.lang.reflect.Method.invoke(Native Method)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:191)
at anywheresoftware.b4a.BA$1.run(BA.java:330)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6776)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1496)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1386)

this has always worked.

What should I correct?

thank you
 
Upvote 0
The code you posted is correct. I guess that you later try to reuse the notification. You can fix it with:
Code: Copy
mNotification.Icon             = "sync_gray_icon"
    mNotification.Sound         = False
    mNotification.Vibrate        = False

    mNotification.SetInfo("Notifica Sync", "Sincronizzazione in corso.....", Null)
        
    mNotification.Notify(mIDNotifyConnection)
    mNotification.Initialize '<-- initialize it so you can later reuse it.
 
Upvote 0
now It's work. But I'm not anderstend?!
thank you
 
Upvote 0
The only thing that you can do with a notification object after calling SetInfo is to show it (with Notify or Service.StartForeground). You cannot change anything else.

The main mistake in your code is that mNotification is a global variable. If it was a local variable then you would have initialized it every time before you try to use it.
 
Upvote 0
all clear Erel,
but it always worked before the update. anyway ok and thanks
 
Upvote 0
Back
Top