VideoAds belongs to the episode the viewer watches: create it when the screen opens, and destroy() it with whatever owns it.
-
Owned by a
ViewModel:destroy()inonCleared(), and in every new Activitytrackits player. The ads survive a rotation, and so does the ad on screen, which outlives the Activity: set its listener from the current screen, again after every recreation, and clear it inonDestroy(), soonAdEndednever reaches a destroyed Activity (a listener left from the old screen also keeps it alive). -
Owned by the Activity, a Fragment or a Compose
DisposableEffect:destroy()in itsonDestroy()(onDispose), every time. A rotation or another configuration change destroys and recreates the Activity, and the ads with it: declareandroid:configChangesfor rotation, as the example app does, so a rotation does not recreate it. -
A
VideoAdsits owner forgot is never released: it holds its player adapter, its ads and their listeners. -
A linear ad runs in the SDK’s own Activity, over yours. Yours is stopped meanwhile and may be destroyed and recreated (a rotation, the system reclaiming memory); with the
VideoAdsin aViewModel, or for a rotation in an Activity that declaresandroid:configChanges, the ad keeps playing, and its end reaches the listener it was shown with. -
A player Activity with
launchMode="singleInstance"is not supported for linear ads: the ad opens in another task, and the viewer returns there. Usestandard,singleToporsingleTask. -
The example app keeps its player Activity across rotation with
android:configChangesand callsads.destroy()in everyonDestroy(). -
The ad holds its listener until
onAdEndedhas run, so a listener that is your Activity stays reachable until the ad ends.