Closed aykutuludag closed 1 month ago
For Android I only detected following issue, happening very rare:
Fatal Exception: java.lang.RuntimeException: Unable to start service com.gdelataillade.alarm.alarm.AlarmService@2c1a71e with null: java.lang.NullPointerException
at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:4712)
at android.app.ActivityThread.access$2000(ActivityThread.java:309)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2236)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:264)
at android.app.ActivityThread.main(ActivityThread.java:8315)
at java.lang.reflect.Method.invoke(Method.java)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:632)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1049)
Following functions called from Home.dart. I make sure the functions only called once. It is just called as setUpAlarms(context) inside initState.
But alarm library logs is kinda weird like library executing alarm function twice. Here is the code (I removed unnecessary parts):
Future<void> setUpAlarms(BuildContext context) async {
await Alarm.init();
// TEMPORARY
if (Platform.isAndroid &&
await Permission.scheduleExactAlarm.status.isGranted == false) {
await Permission.scheduleExactAlarm.request();
}
// TEMPORARY
await Alarm.stop(123);
await Alarm.stop(456);
createAlarm(
123, dateTime, AppLocalizations.of(context).appName, formattedDate);
createAlarm(
456, dateTime2, AppLocalizations.of(context).appName, formattedDate2);
}
Future<void> createAlarm(
int alarmId, DateTime dateTime, String title, String body) async {
final alarmSettings = AlarmSettings(
id: alarmId,
dateTime: dateTime,
assetAudioPath: 'assets/notification.mp3',
loopAudio: false,
vibrate: true,
volume: 1,
androidFullScreenIntent: false,
warningNotificationOnKill: false,
notificationSettings: NotificationSettings(
title: title,
body: body,
));
await Alarm.set(alarmSettings: alarmSettings);
}
Here is the logs:
I/flutter (24813): [Alarm] Alarm with id 63 stopped
I/flutter (24813): [Alarm] Alarm with id 132 stopped
I/flutter (24813): [Alarm] Alarm with id 132 scheduled at 2024-11-06 21:00:00.000
I/flutter (24813): [Alarm] Alarm with id 63 stopped
I/flutter (24813): [Alarm] Alarm with id 132 stopped
I/flutter (24813): [Alarm] Alarm with id 63 scheduled at 2024-10-04 10:00:00.000
I/flutter (24813): [Alarm] Alarm with id 132 scheduled at 2024-11-06 21:00:00.000
Normally according to code, I'm expecting like this:
I/flutter (24813): [Alarm] Alarm with id 63 stopped
I/flutter (24813): [Alarm] Alarm with id 132 stopped
I/flutter (24813): [Alarm] Alarm with id 63 scheduled at 2024-10-04 10:00:00.000
I/flutter (24813): [Alarm] Alarm with id 132 scheduled at 2024-11-06 21:00:00.000
I'm getting the crashes on iOS and Android with this code. Have a nice day. Kind regards.
Hi @aykutuludag !
Thanks for your feedback. I have a few questions:
1) How often the iOS crash occurs ? It crashes when app opens and alarms were previously scheduled right ?
2) About the Android crash, I will take a look later if it's not the priority.
3) About your setUpAlarms
method, have you tried to add await
before each call of createAlarm
?
1) Hard to tell. Sometimes it is crashing three times in a row, sometimes it doesnt crash a long period. Yes, it is crashing on Alarm.init line. It doesn't matter alarms scheduled or not. I saw on Xcode, I guess it was crashing on the following line in your native ios code.
2) It is happening rarely. I will notify you if I saw again on new version. Not encountered for now.
3) I can but isn't await Alarm.set(alarmSettings: alarmSettings); is working for that purpose?
Note: I surroundered with try/catch, doesn't matter still crashing because crash not happened on dart side, it is in swift code.
I was lucky to catch the error when I try. Here is the error my friend.
Alarm plugin version 4.0.1
Describe the bug App crashing when Alarm.init line executed.
Device info All iOS versions
Additional context Firebase Crashlytics report