gpt4 book ai didi

android - 棉花糖中的上下文

转载 作者:行者123 更新时间:2023-11-30 01:56:58 24 4
gpt4 key购买 nike

问题是关于上下文的,它在安装应用程序后第一次运行时返回 null。我需要权限吗?早期版本有效。 Android 开发者预览版 v3 (nexus5)

public class App extends Application {

private static App application;

@Override
public void onCreate() {
super.onCreate();
Log.e("APP::", "CREATE");
application = this;
Log.e("APPLICATION ::", "" + application);
}

public static Context getContext() {
return application != null ? application.getBaseContext() : null;
}
}

最佳答案

您在调用 onCreate() 之前调用了 getContext()。不要那样做。如果可能,根本不要使用对 App 的静态引用。

关于android - 棉花糖中的上下文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32071142/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com