[REQUIRED] Step 1: Describe your environment
Plugin Version
8.0.0
[REQUIRED] Step 2: Describe the problem
AppStateEventNotifier isn't triggering lifecycle events on Android, but it is working fine on iOS.
I am planning on using this event to present an AppOpenAd at the appropriate time. I have this bit of code:
await AppStateEventNotifier.startListening();
_appStateSubscription = AppStateEventNotifier.appStateStream.listen((state) {
if (state != AppState.foreground) {
return;
}
// Do whatever here
});
And if I set a breakpoint right on if (state != AppState.foreground) I never hit it when I foreground/background the app on the Android emulator. On iOS this works fine. It looks like it is related to the code in AppStateNotifier.java, which is:
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch (call.method) {
case "start":
start();
break;
case "stop":
stop();
break;
default:
result.notImplemented();
}
}
According to docs here "Handler implementations must submit a result for all incoming calls, by making a single call on the given MethodChannel.Result callback. Failure to do so will result in lingering Flutter result handlers. The result may be submitted asynchronously and on any thread. Calls to unknown or unimplemented methods should be handled using MethodChannel.Result.notImplemented()."
I believe this needs to be:
@Override
public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
switch (call.method) {
case "start":
start();
result.success(null);
break;
case "stop":
stop();
result.success(null);
break;
default:
result.notImplemented();
}
}
If I make those changes in the AppStateNotifier.java I get the expected results on Android. My Android emulator is running Android version 16.
Steps to Reproduce
- Use GoogleMobileAds flutter plugin.
- Use AppStateEventNotifier.appStateStream to listen for app state changes.
- Set a breakpoint inside the onData function.
- Run the app on iOS, foreground and background it while attached to the debugger and the breakpoint is hit.
- On Android do the same thing and the breakpoint is not hit.
Expected results:
AppStateEventNotifier.appStateStream would post notifications for changes in AppState on both iOS and Android.
Actual results:
This only is working on iOS.
[REQUIRED] Step 1: Describe your environment
Plugin Version
8.0.0
[REQUIRED] Step 2: Describe the problem
AppStateEventNotifier isn't triggering lifecycle events on Android, but it is working fine on iOS.
I am planning on using this event to present an AppOpenAd at the appropriate time. I have this bit of code:
await AppStateEventNotifier.startListening();
_appStateSubscription = AppStateEventNotifier.appStateStream.listen((state) {
if (state != AppState.foreground) {
return;
}
// Do whatever here
});
And if I set a breakpoint right on if (state != AppState.foreground) I never hit it when I foreground/background the app on the Android emulator. On iOS this works fine. It looks like it is related to the code in AppStateNotifier.java, which is:
According to docs here "Handler implementations must submit a result for all incoming calls, by making a single call on the given MethodChannel.Result callback. Failure to do so will result in lingering Flutter result handlers. The result may be submitted asynchronously and on any thread. Calls to unknown or unimplemented methods should be handled using MethodChannel.Result.notImplemented()."
I believe this needs to be:
If I make those changes in the AppStateNotifier.java I get the expected results on Android. My Android emulator is running Android version 16.
Steps to Reproduce
Expected results:
AppStateEventNotifier.appStateStream would post notifications for changes in AppState on both iOS and Android.
Actual results:
This only is working on iOS.