Android Question Bad notification for StartForeground (Error)

ComposerB4A

Member
Licensed User
Longtime User
Hello to all, any person can aid me for this code:

B4X:
** Service (slcall) Create **
** Service (slcall) Start **
** Activity (main) Pause, UserClosed = false **
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentView required: pkg=b4a.example id=1 notification=Notification(vibrate=null,sound=null,defaults=0xfffffff8,flags=0x40)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1044)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)
** Service (retaftercall) Create **
** Service (retaftercall) Start **
android.app.RemoteServiceException: Bad notification for startForeground: java.lang.IllegalArgumentException: contentView required: pkg=b4a.example id=3 notification=Notification(vibrate=null,sound=null,defaults=0xfffffff8,flags=0x40)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1044)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3683)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
at dalvik.system.NativeStart.main(Native Method)

SERVICE1 / SERVICE1 /SERVICE1 / SERVICE1 /SERVICE1 / SERVICE1 /SERVICE1 / SERVICE1 /
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Timer4LimitLlamada As Timer
Dim SWN_SeRetornoAlMain As Int
Dim Notification1 As Notification
Timer4LimitLlamada.Initialize("timer4",5000)
End Sub

Sub Service_Create
SWN_SeRetornoAlMain = 0
Notification1.Initialize
Notification1.Icon = "icon" 'use the application icon file for the notification
Notification1.Vibrate = False
Notification1.Light = False
Notification1.Sound = False
'Service.StartForeground(1, Notification1)
End Sub

Sub Service_Start (StartingIntent As Intent)
Timer4LimitLlamada.Enabled = True
Service.StartForeground(1, Notification1)
End Sub

SERVICE3 / SERVICE3 / SERVICE3 / SERVICE3 / SERVICE3 / SERVICE3 / SERVICE3 / SERVICE3 /
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Notification3 As Notification
End Sub

Sub Service_Create
Notification3.Initialize
Notification3.Icon = "icon" 'use the application icon file for the notification
Notification3.Vibrate = False
Notification3.Light = False
Notification3.Sound = False
'Service.StartForeground(1, Notification3)
End Sub

Sub Service_Start (StartingIntent As Intent)
...
Service.StartForeground(3, Notification3)
End Sub
(fix: original code, in code tags)
 
Last edited:

NJDude

Expert
Licensed User
Longtime User
A couple of things:

1- When posting code PLEASE use the [code] ... [/code] tags.
2- If the code is kind of large, attach your project (on the IDE click on FILE -> EXPORT AS ZIP)
 
Upvote 0
Top