themmfa
themmfa

Reputation: 539

How to end live activity when app terminated flutter

I was trying to implement live activities to my project. I successfully managed that but can't kill the live activities when app terminated. I tried to end the live activity like this:

case AppLifecycleState.detached:
    LiveActivitiesManager().endLiveActivity();

As far as I understand, when user terminated the the app state = detached.However, when app gets terminated live activity's end functionality does not work. If I put this functionality to random button in my app, it works perfectly fine but not when the applifecycle state is detached.How can I solve this problem? I'm using this package plugin for live activities: https://pub.dev/packages/flutter_live_activities

Upvotes: 1

Views: 516

Answers (1)

Giulio987
Giulio987

Reputation: 1

You can use the live_activities package

When you create the activity be sure to pass the removeWhenAppIsKilled parameter:

final activityID = await _liveActivitiesPlugin.createActivity(activityModel,
    removeWhenAppIsKilled: true);

In this way when te app it's ended the live activity also ends

Upvotes: 0

Related Questions