In my application, I start the receiver right at the beginning of the program, its task is to trigger a reminder at the specified time.
schedule module
Only two devices in Crashlytics: OnePlus 8 Pro and Samsung Galaxy S9 throw an error:
Fatal Exception: java.lang.RuntimeException: Unable to start receiver cz.flashcards3000.schedule: java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Object cannot be cast to cz.flashcards3000.b4xpagesmanager
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4564)
at android.app.ActivityThread.-$$Nest$mhandleReceiver()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2312)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Object cannot be cast to cz.flashcards3000.b4xpagesmanager
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:258)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at cz.flashcards3000.schedule.onReceive(schedule.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4548)
at android.app.ActivityThread.-$$Nest$mhandleReceiver()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2312)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by java.lang.ClassCastException: java.lang.Object cannot be cast to cz.flashcards3000.b4xpagesmanager
at cz.flashcards3000.b4xpages._getmanager(b4xpages.java:60)
at cz.flashcards3000.b4xpages._getpage(b4xpages.java:74)
at cz.flashcards3000.schedule$ResumableSub_Receiver_Receive.resume(schedule.java:115)
at cz.flashcards3000.schedule._receiver_receive(schedule.java:72)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at cz.flashcards3000.schedule.onReceive(schedule.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4548)
at android.app.ActivityThread.-$$Nest$mhandleReceiver()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2312)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
How do I fix this? Should I just give up if it only shows up on two devices?
B4X:
Public Sub Start_receiver
Wait For (SetNextEvent) Complete (t As Long)
Wait For (CheckAndRequestNotificationPermission) Complete (HasPermission As Boolean)
If HasPermission Then
Else
Return
End If
Wait For (GetScheduleExactAlarmPermission) Complete (HasPermission As Boolean)
CancelScheduledService(schedule)
StartServiceAtExact(schedule, t, True)
End Sub
schedule:
Private Sub Receiver_Receive (FirstTime As Boolean, StartingIntent As Intent)
' called from StartReceiverAt
If StartingIntent.Action = "" Then
StartNotification
' schedule next event
Wait For (SetNextEvent) Complete (t As Long)
StartReceiverAt(Me, t, True)
End If
' called from notification button
If StartingIntent.Action = "inanhour" Then
Dim p As Period
p.Hours = 1
Dim NextTime As Long = DateUtils.AddPeriod(DateTime.Now, p)
Sleep(1000)
StartReceiverAt(Me, NextTime, True)
ntf.Cancel(4)
End If
End Sub
Private Sub StartNotification
' create notification
Dim sched As String = Starter.loc_schedule
Dim n As NB6
smiley = LoadBitmapResize(File.DirAssets, "ic_launcher.png", 24dip, 24dip, False)
n.Initialize("default", Application.LabelName, "DEFAULT").AutoCancel(True).SmallIcon(smiley)
Dim cs As CSBuilder
n.AddButtonAction(smiley, cs.Initialize.Color(Colors.Green).Bold.Append(Starter.loc_inanhour).PopAll, Me, "inanhour")
ntf = n.Build("Flash cards", sched, "tag1", Main)
ntf.Notify(4)
End Sub
Public Sub SetNextEvent As ResumableSub
Dim cas As String = Starter.rem_time
Dim t, tret As Long
Dim sf As StringFunctions
sf.Initialize
Dim l As List = sf.split(cas, ":")
Dim h As String = l.Get(0)
Dim m As String = l.Get(1)
t = DateUtils.SetDateAndTime(DateTime.GetYear(DateTime.Now), _
DateTime.GetMonth(DateTime.Now), DateTime.GetDayOfMonth(DateTime.Now), h, m, 0)
If t > DateTime.Now Then
tret = t
Else
tret = DateTime.Add(t, 0, 0, 1) 'next day
End If
Return tret
End Sub
Only two devices in Crashlytics: OnePlus 8 Pro and Samsung Galaxy S9 throw an error:
Fatal Exception: java.lang.RuntimeException: Unable to start receiver cz.flashcards3000.schedule: java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Object cannot be cast to cz.flashcards3000.b4xpagesmanager
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4564)
at android.app.ActivityThread.-$$Nest$mhandleReceiver()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2312)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by java.lang.RuntimeException: java.lang.ClassCastException: java.lang.Object cannot be cast to cz.flashcards3000.b4xpagesmanager
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:258)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at cz.flashcards3000.schedule.onReceive(schedule.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4548)
at android.app.ActivityThread.-$$Nest$mhandleReceiver()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2312)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
Caused by java.lang.ClassCastException: java.lang.Object cannot be cast to cz.flashcards3000.b4xpagesmanager
at cz.flashcards3000.b4xpages._getmanager(b4xpages.java:60)
at cz.flashcards3000.b4xpages._getpage(b4xpages.java:74)
at cz.flashcards3000.schedule$ResumableSub_Receiver_Receive.resume(schedule.java:115)
at cz.flashcards3000.schedule._receiver_receive(schedule.java:72)
at java.lang.reflect.Method.invoke(Method.java)
at anywheresoftware.b4a.BA.raiseEvent2(BA.java:221)
at anywheresoftware.b4a.BA.raiseEvent(BA.java:201)
at cz.flashcards3000.schedule.onReceive(schedule.java:42)
at android.app.ActivityThread.handleReceiver(ActivityThread.java:4548)
at android.app.ActivityThread.-$$Nest$mhandleReceiver()
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2312)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loopOnce(Looper.java:240)
at android.os.Looper.loop(Looper.java:351)
at android.app.ActivityThread.main(ActivityThread.java:8423)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:584)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1013)
How do I fix this? Should I just give up if it only shows up on two devices?