Closed m-schmale closed 6 months ago
Hi @m-schmale, I don't believe there's any way to prevent starting the app when a push notification is received on Android, since the system will send an intent to the app to handle the incoming notification.
One strategy I've seen is to check the value of WidgetsBinding.instance?.lifecycleState
before making requests (or use a listener to observe state changes and act accordingly). When a push is received in the background, the state should be AppLifecycleState.detached
vs. a state of AppLifecycleState.resumed
that you'd see when the app is launched in the foreground.
@jyaganeh Thanks a lot, this was really helpful. 👍 I trigger the API calls in the initState and the didChangeAppLifecycleState now. I still have to test this more but it seems to be working just fine.
Preliminary Info
What Airship dependencies are you using?
airship_flutter: 7.3.1
Report
What unexpected behavior are you seeing?
We have the problem that at least on Android the app (or the main method) is started from the terminated state when we receive a push message. Can this be prevented? This is problematic because unnecessary API calls are made every time.
What is the expected behavior?
We expect the app not to be started from terminated state when we receive a push message.
What are the steps to reproduce the unexpected behavior?
Could you please help us with this?