Issue
I have implemented the YouTube intent from a Fragment when a user clicks on an item in an app's RecyclerView cell. The click event is handled in xml via Data Binding and passed to the bound ViewModel which passes the LiveData value representing the click event to the Fragment.
startActivity(YouTubeIntents.createPlayVideoIntentWithOptions(activity, content.id, false, false))
However, after triggering onBackPressed()
to close the activity launched from YouTube and returning to the original app screen, the YouTube activity reappears when the screen is rotated as if the YouTube activity's finish()
method has not been called.
Expected
Rotating the screen after closing the YouTubeActivity does not trigger the YouTubeActivity to re-show unexpectedly.
Attempted Solutions
- Experimented with changing the context passed into the Intent from
context
toactivity
. - Called
context.startActivity(...)
from the Fragment as opposed tostartActivity(...)
- Added a flag to the new activity intent:
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY)
as per this answer. - Wrapped YouTube intent in a "headless" Fragment (a Fragment with no UI) in order to try and control the lifecycle.