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

Shutting down VM #6

Open
xxzj990 opened this issue Jan 19, 2021 · 5 comments
Open

Shutting down VM #6

xxzj990 opened this issue Jan 19, 2021 · 5 comments

Comments

@xxzj990
Copy link

xxzj990 commented Jan 19, 2021

When I call FlutterForegroundServicePlugin.startPeriodicTask,get the following error:

D/AndroidRuntime( 7848): Shutting down VM E/AndroidRuntime( 7848): FATAL EXCEPTION: main E/AndroidRuntime( 7848): Process: xxx, PID: 7848 E/AndroidRuntime( 7848): java.lang.RuntimeException: Unable to start service com.saywut.flutter_foreground_service_plugin.FlutterForegroundService@204d1b2 with Intent { act=START_FOREGROUND_TASK cmp=xxx/com.saywut.flutter_foreground_service_plugin.FlutterForegroundService }: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.BinaryMessenger.setMessageHandler(java.lang.String, io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler)' on a null object reference E/AndroidRuntime( 7848): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3057) E/AndroidRuntime( 7848): at android.app.ActivityThread.access$2200(ActivityThread.java:165) E/AndroidRuntime( 7848): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1467) E/AndroidRuntime( 7848): at android.os.Handler.dispatchMessage(Handler.java:102) E/AndroidRuntime( 7848): at android.os.Looper.loop(Looper.java:150) E/AndroidRuntime( 7848): at android.app.ActivityThread.main(ActivityThread.java:5546) E/AndroidRuntime( 7848): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime( 7848): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794) E/AndroidRuntime( 7848): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684) E/AndroidRuntime( 7848): Caused by: java.lang.NullPointerException: Attempt to invoke interface method 'void io.flutter.plugin.common.BinaryMessenger.setMessageHandler(java.lang.String, io.flutter.plugin.common.BinaryMessenger$BinaryMessageHandler)' on a null object reference E/AndroidRuntime( 7848): at io.flutter.plugin.common.MethodChannel.setMethodCallHandler(MethodChannel.java:119) E/AndroidRuntime( 7848): at com.saywut.flutter_foreground_service_plugin.FlutterForegroundServicePlugin.setupChannels(FlutterForegroundServicePlugin.java:45) E/AndroidRuntime( 7848): at com.saywut.flutter_foreground_service_plugin.FlutterForegroundServicePlugin.registerWith(FlutterForegroundServicePlugin.java:23) E/AndroidRuntime( 7848): at com.saywut.flutter_foreground_service_plugin.FlutterForegroundService.createFlutterEngineAndBackgroundChannel(FlutterForegroundService.java:220) E/AndroidRuntime( 7848): at com.saywut.flutter_foreground_service_plugin.FlutterForegroundService.onStartCommand(FlutterForegroundService.java:95) E/AndroidRuntime( 7848): at android.app.ActivityThread.handleServiceArgs(ActivityThread.java:3040) E/AndroidRuntime( 7848): ... 8 more I/Process ( 7848): Sending signal. PID: 7848 SIG: 9

@SayWut
Copy link
Owner

SayWut commented Jan 19, 2021

what is your flutter?
what is your android version?

paste the code sample when the exception occurs

from what I see, it is happens when you try to start the service task but I need your code to understand why it happens

@xxzj990
Copy link
Author

xxzj990 commented Jan 21, 2021

@SayWut thank you for your reply.

I don't know how it happened.I will directly copy your sample code to main.dart and report this problem.It may be related to a library I referenced.

At present, I have made the following changes to the library code, and the problem no longer occurs:

private void setupChannels(BinaryMessenger messenger, Context context)
  {
    if(messenger != null) {
        FlutterForegroundServiceChannelHandler handler = new FlutterForegroundServiceChannelHandler(context);

        methodChannel = new MethodChannel(messenger, FOREGROUND_CHANNEL_CHANNEL);
        methodChannel.setMethodCallHandler(handler);
    }
  }

flutter doctor:

Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 1.22.5, on Microsoft Windows [Version 10.0.19041.572], locale zh-CN)

[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[!] Android Studio (version 4.1.0)
    X Flutter plugin not installed; this adds Flutter specific functionality.
    X Dart plugin not installed; this adds Dart specific functionality.
[√] IntelliJ IDEA Ultimate Edition (version 2019.2)
[√] VS Code, 64-bit edition (version 1.47.0)
[√] Connected device (1 available)

! Doctor found issues in 1 category.

@SayWut
Copy link
Owner

SayWut commented Jan 21, 2021

@xxzj990 But if the messnger is null and we do your solution the channels between flutter and android will not astublish and nothing will work

@SayWut
Copy link
Owner

SayWut commented Jan 22, 2021

can you copy your code to here?

@Piero512
Copy link

I too have this problem. I'm not entirely sure why Flutter is calling it like it was a V1 embedding plugin, but it does now I guess.
I'm using Flutter 2.2.3 stable. I can't reproduce it on the example one, but the stack trace seems exactly the same. Maybe the plugin needs to be ServiceAware?

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