Error running with android_alarm_manager
See original GitHub issueAdded android_alarm_manager package to my project, got this error:
I/AlarmService( 5386): Starting AlarmService...
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): Failed to handle method call
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): java.lang.NullPointerException: Attempt to invoke virtual method 'android.os.Looper android.app.Activity.getMainLooper()' on a null object reference
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.google.android.gms.common.api.GoogleApi.<init>(Unknown Source:50)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.google.android.gms.location.FusedLocationProviderClient.<init>(Unknown Source:8)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.google.android.gms.location.LocationServices.getFusedLocationProviderClient(Unknown Source:2)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.lyokone.location.LocationPlugin.<init>(LocationPlugin.java:95)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.lyokone.location.LocationPlugin.registerWith(LocationPlugin.java:116)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:29)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.ngsalesrepapp.Application.registerWith(Application.java:19)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at io.flutter.plugins.androidalarmmanager.AlarmService.startAlarmService(AlarmService.java:114)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at io.flutter.plugins.androidalarmmanager.AndroidAlarmManagerPlugin.startService(AndroidAlarmManagerPlugin.java:79)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at io.flutter.plugins.androidalarmmanager.AndroidAlarmManagerPlugin.onMethodCall(AndroidAlarmManagerPlugin.java:52)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:201)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at io.flutter.view.FlutterNativeView$PlatformMessageHandlerImpl.handleMessageFromDart(FlutterNativeView.java:188)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:202)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at android.os.MessageQueue.nativePollOnce(Native Method)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at android.os.MessageQueue.next(MessageQueue.java:325)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at android.os.Looper.loop(Looper.java:142)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at android.app.ActivityThread.main(ActivityThread.java:6541)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
E/MethodChannel#plugins.flutter.io/android_alarm_manager( 5386): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
I/flutter ( 5386): PlatformException(error, Attempt to invoke virtual method 'android.os.Looper android.app.Activity.getMainLooper()' on a null object reference, null)
I/AlarmService( 5386): AlarmService started!
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Error -32601 received from application: Method not found
Thought it might be related to https://github.com/flutter/plugins/pull/1255 which I had a while back. However, after removing each package one at a time I found that the location package was causing this. I recreated the error/issue in a new project with only android_alarm_manager and the location package installed. I have a quite a number of other packages installed that don’t cause any issues. Here is my flutter doctor:
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17134.648], locale en-ZA) [√] Android toolchain - develop for Android devices (Android SDK version 28.0.3) [√] Android Studio (version 3.3) [√] Android Studio (version 3.0) [√] IntelliJ IDEA Community Edition (version 2018.3) [√] VS Code (version 1.32.3) [√] Connected device (1 available)
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (3 by maintainers)
Thanks a lot for your quick response & releasing it so soon again
FYI @Lyokone, #162 will prevent crashing when a plugin with background execution support attempts to register this plugin without an
Activity
, but will prevent users from using this plugin from the background. You might want to consider utilizing aContext
for grabbing the location service and only checkactivity != null
around calls that actually need anActivity
.