Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Example App Crashes on Android 6 #881

Closed
zjamshidi opened this issue Oct 30, 2020 · 9 comments
Closed

Example App Crashes on Android 6 #881

zjamshidi opened this issue Oct 30, 2020 · 9 comments

Comments

@zjamshidi
Copy link

Describe the bug
When the app is terminated and daily/weekly reminder fires, the app crashes.

To Reproduce

  1. Run the example app (cloned from the git repository without any changes) on Android 6
  2. schedule daily/weekly reminder
  3. terminate the app and wait for the reminder
  4. app crashes

Expected behavior
no crash

Sample code to reproduce the problem
the provided example

here is the crash's stack trace:

Caused by r.b.a.y.g: No time-zone data files registered
       at org.threeten.bp.zone.ZoneRulesProvider.getProvider(ZoneRulesProvider.java)
       at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java)
       at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java)
       at org.threeten.bp.ZoneId.of(ZoneId.java)
       at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.getNextFireDateMatchingDateTimeComponents(FlutterLocalNotificationsPlugin.java)
       at com.dexterous.flutterlocalnotifications.FlutterLocalNotificationsPlugin.zonedScheduleNextNotificationMatchingDateComponents(FlutterLocalNotificationsPlugin.java)
       at com.dexterous.flutterlocalnotifications.ScheduledNotificationReceiver.onReceive(ScheduledNotificationReceiver.java)
       at android.app.ActivityThread.handleReceiver(ActivityThread.java:2743)
       at android.app.ActivityThread.access$1800(ActivityThread.java:157)
       at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1433)
       at android.os.Handler.dispatchMessage(Handler.java:102)
       at android.os.Looper.loop(Looper.java:148)
       at android.app.ActivityThread.main(ActivityThread.java:5525)
       at java.lang.reflect.Method.invoke(Method.java)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:730)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:620)
@MaikuB
Copy link
Owner

MaikuB commented Oct 31, 2020

  1. Is this issue only occurring for you on Android 6? What happens if you on more recent versions of Android like 10?
  2. Are you able to reproduce this on an emulator? I don't have an Android 6 device so need to use an emulator
  3. What value is being reported for timeZoneName (see
    final String timeZoneName = await platform.invokeMethod('getTimeZoneName');
    ) when you run the example app?

@zjamshidi
Copy link
Author

  1. I have tested on Android 9 and it works fine. Also, I tried scheduling a reminder for the next 5 seconds and it was fine on Android 6.
    The crash is happening for "weekly/daily reminders, when the app is in the background, on Android 6"
  2. I didn't test on the emulator. You can give it a try.
  3. I think the timezone was set correctly. I remember "Asia/..."
    Again the crash only happens when the app is in the background.

@MaikuB
Copy link
Owner

MaikuB commented Oct 31, 2020

This should be fixed now

@MaikuB MaikuB closed this as completed Oct 31, 2020
@reovo
Copy link

reovo commented Nov 4, 2020

I'm also facing same issue on Android v6.0.1. I cannot reproduce it on Android 9, or 10.

E/MethodChannel#dexterous.com/flutter/local_notifications(25815): Failed to handle method call
E/MethodChannel#dexterous.com/flutter/local_notifications(25815): org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered
E/MethodChannel#dexterous.com/flutter/local_notifications(25815): 	at org.threeten.bp.zone.ZoneRulesProvider.getProvider(ZoneRulesProvider.java:165)
E/MethodChannel#dexterous.com/flutter/local_notifications(25815): 	at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:122)
E/MethodChannel#dexterous.com/flutter/local_notifications(25815): 	at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
E/MethodChannel#dexterous.com/flutter/local_notifications(25815): 	at org.threeten.bp.ZoneId.of(ZoneId.java:358)
E/flutter (25815): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: PlatformException(error, No time-zone data files registered, null, org.threeten.bp.zone.ZoneRulesException: No time-zone data files registered
E/flutter (25815): 	at org.threeten.bp.zone.ZoneRulesProvider.getProvider(ZoneRulesProvider.java:165)
E/flutter (25815): 	at org.threeten.bp.zone.ZoneRulesProvider.getRules(ZoneRulesProvider.java:122)
E/flutter (25815): 	at org.threeten.bp.ZoneRegion.ofId(ZoneRegion.java:143)
E/flutter (25815): 	at org.threeten.bp.ZoneId.of(ZoneId.java:358)

I'm using latest flutter_local_notifications: ^3.0.1+2 version

code:

await flutterLocalNotificationsPlugin.zonedSchedule(
        messageId, "notification title", "notification message",
          tz.TZDateTime.now(tz.local).add(Duration(seconds: 5)),
        platformChannelSpecifics,
        uiLocalNotificationDateInterpretation: UILocalNotificationDateInterpretation.absoluteTime,
        androidAllowWhileIdle: true,
        matchDateTimeComponents: DateTimeComponents.time);

@MaikuB
Copy link
Owner

MaikuB commented Nov 4, 2020

I've tried this with the example app and pointed it to 3.0.1+2 (instead of using the path) and couldn't reproduce the issue so going to need a link to repository that reproduces the issue on an Android 6 emulator. I wonder if your app is still pulling an older version and just needs a clean and rebuild

@reovo
Copy link

reovo commented Nov 4, 2020

MaikuB, i have tried an example app, and with example it works fine..
so i guess it some kind of configuration that is missing. i'm trying to dig in..
timezone in both my app and example app is the same Europe/Vilnius

I have tried flutter clean. didn't help. I'll let you know if i'll find something

@reovo
Copy link

reovo commented Nov 4, 2020

Ok, obviously the problem is with
AndroidThreeTen.init(context);

I have added this line inside my app MainActivity.kt just after registering an app

import com.jakewharton.threetenabp.AndroidThreeTen

class MainActivity: FlutterActivity() {
    override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
        AndroidThreeTen.init(context);
    }
}

of course also added a dependency in build.gradle

implementation 'com.jakewharton.threetenabp:threetenabp:1.0.3'

Everything is working now on Android v6, also tried on Android v10

My assumption that https://github.com/MaikuB/flutter_local_notifications/blob/4111de48bdbedab632f65ac2892159ba1d22543a/flutter_local_notifications/android/src/main/java/com/dexterous/flutterlocalnotifications/FlutterLocalNotificationsPlugin.java#L148 not triggered in my case.

I can try to modify plugin code and identify exact values if you want.
VERSION.SDK_INT & VERSION_CODES.O

@reovo
Copy link

reovo commented Nov 5, 2020

I have reviewed your code, and it helped me to understand the issue.

If we initalize await flutterLocalNotificationsPlugin.initialize(...) once, then during that session, all notifications works fine.
However if we restart an app and do not initialize, then it stops working. ( imagine you have an "on boarding" process where you ask for permissions once )

I assume that there are 3 options to fix the issue:

  1. I've posted above
  2. Everytime we launch a flutter app, we have to call await flutterLocalNotificationsPlugin.initialize(...) somewhere before using scheduling notifications.
  3. Or you should update the plugin and add reference
    from private void zonedSchedule(MethodCall call, Result result) {
    to initAndroidThreeTen(context);

@MaikuB
Copy link
Owner

MaikuB commented Nov 5, 2020

@reovo The original scenario reported by @zjamshidi was around after scheduling a recurring notification then once triggered, it failed to schedule the next instance. I thought you had the same scenario. initalize should always be called as without it you will not be able to process any events on when the user taps on a notification. It is described as the first step to do when using the plugin (see here) as well

Edit: I may look at adding an assertion to make sure the plugin is initialised before calling methods that trigger/schedule a notification. PRs on this are welcome too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants