UnityPlayerActivity getContext() 替换
UnityPlayerActivity getContext() substitution
UnityPlayerActivity 中是否有 getContext 的替代方法?
我想要如下代码。
Activity.getContext()
回答来自here
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
playerActivityContext = actClass.GetStatic< AndroidJavaObject >("currentActivity");
}
或者您可以使用下面来自 here
的代码
public class Main extends UnityPlayerActivity {
public static Context mContext;
@Override
protected void onCreate(Bundle bundle)
{
super.onCreate(bundle);
mContext = this;
}
}
getContext() is not defined in an Activity。它在 View 中用于获取对封闭 context[= 的引用22=](一个Activity).
请阅读下面的答案,希望对您有所帮助。
Difference between getContext() , getApplicationContext() , getBaseContext() and "this"
UnityPlayerActivity 中是否有 getContext 的替代方法?
我想要如下代码。
Activity.getContext()
回答来自here
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
playerActivityContext = actClass.GetStatic< AndroidJavaObject >("currentActivity");
}
或者您可以使用下面来自 here
的代码public class Main extends UnityPlayerActivity {
public static Context mContext;
@Override
protected void onCreate(Bundle bundle)
{
super.onCreate(bundle);
mContext = this;
}
}
getContext() is not defined in an Activity。它在 View 中用于获取对封闭 context[= 的引用22=](一个Activity).
请阅读下面的答案,希望对您有所帮助。
Difference between getContext() , getApplicationContext() , getBaseContext() and "this"