adee42 / flutter_keyboard_visibility

MIT License
237 stars 142 forks source link

Crash when using with Firebase Messaging, because of Application initilalisation. #38

Open droidluv opened 4 years ago

droidluv commented 4 years ago
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'android.app.Application android.app.Activity.getApplication()' on a null object reference
E/AndroidRuntime( 5340):    at com.github.adee42.keyboardvisibility.KeyboardVisibilityPlugin.registerWith(KeyboardVisibilityPlugin.java:107)
E/AndroidRuntime( 5340):    at io.flutter.plugins.GeneratedPluginRegistrant.registerWith(GeneratedPluginRegistrant.java:38)
E/AndroidRuntime( 5340):    at com.example.app.Application.registerWith(Application.kt:17)
E/AndroidRuntime( 5340):    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.startBackgroundIsolate(FlutterFirebaseMessagingService.java:164)
E/AndroidRuntime( 5340):    at io.flutter.plugins.firebasemessaging.FlutterFirebaseMessagingService.onCreate(FlutterFirebaseMessagingService.java:77)
E/AndroidRuntime( 5340):    at android.app.ActivityThread.handleCreateService(ActivityThread.java:3953)

the crash happens in line 107 of https://github.com/adee42/flutter_keyboard_visibility/blob/master/android/src/main/java/com/github/adee42/keyboardvisibility/KeyboardVisibilityPlugin.java

at registrar.activity().getApplication().registerActivityLifecycleCallbacks(instance); where registrar.activity() return null because registration is happening in Application class, can you have a null check set for this.

droidluv commented 4 years ago

I just looked at the PR's, because I was thinking of making one and found somebody has already beat me to it, and that fix was forked over and is now available over here https://github.com/MisterJimson/flutter_keyboard_visibility and this is the working fine!

jmgjmg commented 4 years ago

The issue is due to the fact that the Firebase Messaging plugin is creating a headless isolate (not associated to a view or activity) which results in the call to registerWith() method with a null activity.

registrar.activity().getApplication().registerActivityLifecycleCallbacks(instance);

g-balas commented 4 years ago

@droidluv I can confirm that fixed it for me. It was the facebook_login plugin that messed it up.

sgehrman commented 4 years ago

Any plan on fixing this? Same issue.