Post

Replies

Boosts

Views

Activity

Remember Live Activity reference across app launches
I have a use case where a user may want to swap out one live activity for a different one. Starting a new activity while an existing one has no effect unless you end the previous one first. When ActivityKit starts a live activity you’re given an ID / reference to that activity to store in a variable - this lets you end the old one before starting a new one. If the app is closed, this reference is lost but the live activity continues. But, it then becomes “un-endable” since I no longer have a reference to it. So I become stuck in this place where I can’t start a new activity without ending the old one, but I no longer have a reference to the old one, resulting in it basically being orphaned. What’s the recommended way of achieving this? Is there a safe way to store my reference to the live activity across app restarts? Or alternatively, is there a way to end all live activities for my app without a reference to them? Is there a way to get an ongoing live activity for the app?
1
1
798
Oct ’22