0

Sidenote: This question is similar in nature to e.g. Leave receiver running after sender stop , though I cannot find any mention of stop or stopApplication in my code. Also, though similar questions exist, they usually provide dead links and typically do not specifically address android tv receiver applications.


Scenario

  1. Android device A starts casting to an android TV. This causes an android TV application to be launched as the receiver application (see https://developers.google.com/cast/docs/android_tv_receiver).
  2. Android device B connects to the same android TV, joining the existing session
  3. B disconnects (cast button -> "stop casting")

What I want to happen

  • Receiver-side (tv) onSenderDisconnected should be called only for B
  • Android TV application should remain running

What actually happens

  • Receiver-side (tv) onSenderDisconnected is called for both A & B
  • Android TV application is closed

Question

  • Why are all sender applications disconnected and the android TV application closed as soon as a single sender disconnects?
  • How can I leave the android TV application running after a sender is disconnected?
Felix ZY
  • 674
  • 6
  • 14
  • Cen you elaborate what listeners you are registering? Also regarding `onSender...` methods, I can only find references to that here: https://developers.google.com/interactive-media-ads/docs/sdks/cast/dai/receiver Are you writing a HTML5 receiver app or an actual android app? – JensV May 20 '21 at 09:36
  • @JensV I'm using `CastReceiverContext.registerEventCallback` to register a `CastReceiverContext.EventCallback`. This is 100% android, no html5 involved. – Felix ZY May 20 '21 at 09:54

1 Answers1

1

I just implemented this feature in my app, did you try to do something like this?

In your Application class:

CastReceiverContext.getInstance().registerEventCallback(object: CastReceiverContext.EventCallback() {

        override fun onSenderConnected(info: SenderInfo) {
            setupPlayerData()
        }

        override fun onSenderDisconnected(eventInfo: SenderDisconnectedEventInfo) {

            val intent = Intent(this@FooApplication, CastLauncherActivity::class.java).apply {
                flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
            }
            startActivity(intent)
        }
    })

Basically what I did in my app is to open a Splash Screen with a Cast symbol. I just checked and you can open any Activity from onSenderConnected() or onSenderDisconnected

Nicolas Jafelle
  • 2,661
  • 2
  • 24
  • 30
  • No, I haven't tried this but won't this simply start a new activity when the sender disconnects? I.e. I want my activity to _remain_ running. Consider e.g. a video player app where the casting device is disconnected due to inactivity during playback - I wouldn't want the video interrupted by that. – Felix ZY Jun 12 '21 at 22:03
  • Yes, in fact it blinks when exit the current screen and open the new Activity. What if you combine this with singleTask or singleInstance? will that make sense?? Honestly you are trying to do something that the Google Cast is completely not able to do because of the foundations of the framework. If you click on "Stop casting" that menas stop everything, every connection between the Sender and the Receiver. Let me try to do something else but definitely it will be a workaround and a bad practice for sure. – Nicolas Jafelle Jun 13 '21 at 22:48