'Unity Player currentActivity Always returns null on Android Device

Unity player current activity always returns null on Android device as well

Following is my code

_androidPluginClass = new AndroidJavaClass(androidPluginName);
AndroidJavaClass playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
AndroidJavaObject activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
_androidPluginClass.SetStatic<AndroidJavaObject>("mainActivity", activity);

How to fix this?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source