UnityPlayerForActivityOrService instantiated via Service?

UnityPlayerForActivityOrService implies it can be used from a service, as UnityPlayer was capable in the past. However, there are several calls in UnityPlayerForActivityOrService that assume that passed context is bound to Activity, such as,

    public static boolean isInMultiWindowMode(Activity var0) {
        return PlatformSupport.NOUGAT_SUPPORT ? var0.isInMultiWindowMode() : false;

Which fails if the UnityPlayerForActivityOrService is instantiated from a service.

How do I instantiate a UnityPlayer that is bound to a service (long-running and used as an overlay view via WindowManager) instead of an activity (which can be terminated by OS at any point if minmized).

These shouldn't be called if context is not activity. It's a bug if they are called.

Ok, should I submit a bug report?

There are only 2 ways to resume Unity -> onResume function which assumes the context is an activity and will crash otherwise:

if (!MultiWindowSupport.isInMultiWindowMode(this.mActivity) || MultiWindowSupport.isMultiWindowModeChangedToTrue(this.mActivity)) {

Second is resume() which is now deprecated. (but at least doesn't call isInMultiWindowMode)

Unity doesn't officially support instantiating from Service, the only case where it was somewhat supported is WallpaperService, for which we have automatic coverage which ensures it works.

I am not exactly sure about your case, could submit a bug with repro project attached, so we can investigate.

I am guessing here your WallpaperService tests are not failing because it's using the deprecated resume() method. What happens when that's gone?

I'll create a sample project and attach it shortly.

Here is a sample project:

Could you please report via Unity's bug reporter - https://unity.com/releases/editor/qa/bug-reporting ? Thank you

1 Like