我有一个场景,我想在电视上开发一个应用程序,如果用户正在 Youtube 上观看一些视频,如果我想加载我的应用程序,那么它会在前台启动,我会显示一些透明背景的信息并且应用程序后面将继续工作,就像如果应用程序后面是 Youtube 那么它应该会继续播放而不会暂停。
如果可能请帮帮我?如果是,我该如何实现?
最佳答案
In Manifest Define Activity theme as transulent :
<activity android:name=".YourActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar" />
For Transulent Activity life cycle differs from Non-transulent Activity :
For Non-transulent Activity-A if any other Activity-B comes on top of it then Activity-A will be in onStop state.
Activity-A if any other Activity-B comes on top of it then Activity-A will be in onPause stateBut where as For Transulent
然后这样做:
@Override
public void onPause() {
super.onPause();
if (mVideoView.isPlaying()) {
// Argument equals true to notify the system that the activity
// wishes to be visible behind other translucent activities
if (! requestVisibleBehind(true)) {
// App-specific method to stop playback and release resources
// because call to requestVisibleBehind(true) failed
stopPlayback();
}
} else {
// Argument equals false because the activity is not playing
requestVisibleBehind(false);
}
}
I did implementation it worked go through this it will help u for sure :
https://developer.android.com/training/tv/playback/options.html
If you requirement is related to Picture in Picture try this :
https://developer.android.com/guide/topics/ui/picture-in-picture.html
关于android - 只显示通知,后台应用保持 onResume,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49008102/