Understanding Android TV activity lifecycle

Viewed 232

It has been a couple of months since I started to develop for android TV, I have an app fully working which displays two channels (Live and OnDemand) and some programs in the home screen:

enter image description here

I started the project using: https://github.com/googlecodelabs/tv-recommendations

which is DEPRECATED but it is the only working example I could find on the entire web (better than nothing).

My problem at the moment is that I'm not sure how to deal with the lifecycle of my Activity that manage the Intents generated by the home screen itself.

I will try to describe it with an example:

Starting from the app completely closed I click on OnDemand3 Program, here is the lifecycle observed:

Create -> Start -> Resume -> DO STUFF

Once that I press home on the remote the lifecycle terminates correctly:

DO STUFF -> Pause -> Stop [-> Destroy (not guaranteed)]

A this point the app stays in the background (doesn't get destroyed immediately). Everything seem fine and I can watch another Program pressing on the desired one (for example OnDemand2). Everything works as expected an the lifecycle is:

Create -> Start -> Resume -> DO STUFF -> Pause -> Stop

I can play any other Program and it will work as expected but there is an exception: if at some point later I play again the program that created the activity the first time (in the example OnDemand3) the lifecycle changes:

Restart -> Start -> Resume -> DO STUFF -> Pause -> Stop

The problem is that my Activity decide what video to play based on the Intent passed from the home screen, the fact is that when the Activity goes through Restart the Intent is not updated to the one of OnDemand3, rather, the Intent of the second last played Program is used!

I tried many workaround but the problem is that you get a Restart either with pressing on the first Program that created the Activity or with the press of the standby button. I haven't find any way to discriminate between the two Restarts and at this point I don't think there is a way.

Using the DEPRECATED project from google I can observe the same behavior which means that probably something has changed, but I really can't find a solution to this rather weird lifecycle.

Could anyone at least try to point me in the correct direction?

P.S. sorry If I haven't posted any code but I have a lot of it and the important part is scattered around the files, since the problem is present as well in https://github.com/googlecodelabs/tv-recommendations you could give a look there

0 Answers
Related