Search code examples
android-tvgoogle-assistant-sdk

Why the activity under google assistant go onPause in Android TV?


I am working an app on android tv. We are discussing about the reason why activity go onPause when Google Assistant is active. We found this problem happened suddenly in one day.

After tracing this problem for many days, we found that Assistant page cover on our app as a activity. That's the reason why my app go onPause. But I want to know the reason why it could suddenly become an activity.

Here is my observation of activity. I use "adb shell dumpsys activity" to check activity status.

Without going to onPause situation

Running activities (most recent first):
    Run #0: ActivityRecord{2d9fe0 u0 com.google.android.katniss/com.google.android.apps.tvsearch.app.launch.trampoline.SearchActivityTrampoline t12 f}
Running activities (most recent first):
    Run #0: ActivityRecord{32ee7d7 u0 com.sv.n973796_home/.atv.ui.HomeActivity t5}
Running activities (most recent first):
    Run #0: ActivityRecord{f0c9842 u0 com.sv.n973796_home/.LauncherMainActivity t3}

Going to onPause situation

Running activities (most recent first):
    Run #0: ActivityRecord{bdce69a u0 com.google.android.katniss/com.google.android.apps.tvsearch.results.activity.SearchResultActivity t825}
Running activities (most recent first):
    Run #2: ActivityRecord{87c5fd1 u0 com.sv.n973796_home/.common.ui.HomeActivity t817}
    Run #1: ActivityRecord{28d1d6c u0 com.sv.n973796_home/.LauncherMainActivity t817}

My questions here:

  1. Is there any document about this changing?(between "com.google.android.apps.tvsearch.app.launch.trampoline.SearchActivityTrampoline" and "com.google.android.apps.tvsearch.results.activity.SearchResultActivity")

  2. Does this problem relate to my SDK version?(sdk version in gradle or SDK manager?)

  3. Is there any way to check the version of com.google.android.katniss? and could I choose it?


Solution

    1. There is no specific documentation about this changing. It's due to a change with how ATV Assistant is implemented.

    2. No. It is entirely based on which version of ATV Assistant is on the device.

    3. You can manually check the ATV Assistant version in system settings (Apps -> All Apps -> Show system apps, Google). You may be able to programmatically determine the version on the device by checking package manager (I don't recall if that requires a permission), but you don't want to do that. You can't guarantee that the behavior will be the same in different versions and updates are being regularly released.

    I'd ask what specific issue you have with onPause being triggered (or not triggered) and start from there because ATV Assistant isn't the only reason that onPause could be called. For example, if your app handles video playback you would want to stop the player in onPause() in Android 6.0 and earlier and then in onResume() you would check if it was playing when onPause() was invoked and trigger playback again if it was. You shouldn't care about whether onPause() was invoked due to the Assistant coming to the foreground or the OS displaying an alert dialog. In versions of Android after that, you can simply have that logic in onStop/onStart, since the onStop() lifecycle method is guaranteed to be called quickly when the activity is no longer visible.