Search code examples
androidandroid-activitychromecastlifecycle

How to keep an activity alive after back button press?


I'm developing a chromecast streaming app for Android. In Activity A the user chooses between different playable items and then is moved to Activity B, which holds the Chromecast controls. When the user hits the back button he is presented with Activity A from where he can choose another video while the casting of the first one is still running on the TV. The problem is that after the back button is pressed, Activity B which holds the controls (for example: seek bar with the video progress) is destroyed and there is no way the user can interact with the destroyed controls anymore. Is there a way I can keep Activity B alive? I'm a novice developer and I have no experience with fragments, so I'm looking for a solution which does not involve their usage...


Solution

  • I strongly suggest you read the Cast UX Checklist where this issue is brought up and addressed. The ways to address that are:

    On Android, you can use the CastCompanionLibrary that provides all of these for you with minimal coding.