android - 只显示通知,后台应用保持 onResume

标签 android android-tv

我有一个场景,我想在电视上开发一个应用程序,如果用户正在 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/

相关文章:

android - 线程和处理程序

android - 在 Android 中支持背景颜色的圆角 ImageView?

java - 如何更改非 sp 比例的字体大小?

android - 将数据从 dialogfragment 传递到 fragment

unity3d - 仅适用于 Android TV 的 Android Manifest - 支持的设备太少?

Flutter 如何制作可选择/可聚焦的小部件

java - 服务重启后出现 DeadObjectException

NVIDIA TV 上的 Ubuntu - CUDA 驱动程序版本对于 CUDA 运行时版本不足

android-tv - 通过ADB连接小米安卓盒子

android - 如何在 Android 电视应用程序中将 View 设置为可聚焦?