I am experimenting with using the flutter accessiblity service from a flutter foreground task. When I try to listen to the events in the foreground task then I get the following exception if the app is closed:
PlatformException(error, Attempt to invoke virtual method 'void android.app.Activity.startActivityForResult(android.content.Intent, int)' on a null object reference, null, java.lang.NullPointerException: Attempt to invoke virtual method 'void android.app.Activity.startActivityForResult(android.content.Intent, int)' on a null object reference
at slayer.accessibility.service.flutter_accessibility_service.FlutterAccessibilityServicePlugin.onMethodCall(FlutterAccessibilityServicePlugin.java:56)
at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
It is probably because the package is trying to use an Activity context to call startActivityForResult. But this context may not be available in a foreground service.