尝试从 Android 中的应用程序上下文访问资源
我有一个单例,它在我的应用程序(ACCU.class)上保存了大量信息。 我正在使用应用程序上下文进行一次初始化和一次完成。 其中一个关键功能是另一个名为 IMCDefinition 的单例,它从名为 imc.xml 的原始资源中读取。如果我从 Activity Context 调用行 IMCDefinition.getInstance(getResources().openRawResource(R.raw.imc));
,它就会起作用。从应用程序上下文来看,它不... 代码如下:
public class App extends Application
{
public App()
{
IMCDefinition.getInstance(getResources().openRawResource(R.raw.imc));
ACCU.getInstance(this);
System.out.println("Global ACCU Object Initialized");
}
}
I have a singleton that holds a lot of information on my App (ACCU.class).
I'm using the application context to do a single initialization and single finishing.
One of the key features is another singleton called IMCDefinition that reads from a raw resource named imc.xml. If I call the line IMCDefinition.getInstance(getResources().openRawResource(R.raw.imc));
from an Activity Context it works. From an Application context it doesn't...
Following goes the code:
public class App extends Application
{
public App()
{
IMCDefinition.getInstance(getResources().openRawResource(R.raw.imc));
ACCU.getInstance(this);
System.out.println("Global ACCU Object Initialized");
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
完毕!您不会弄乱此类中的构造函数。 onCreate() 是要走的路。把你的代码放在那里。忘记这个问题吧。我应该把这个放在一个单独的答案中吗?
Done! You don't get to mess with the Constructor in this class. onCreate() is the way to go. Put your code there. Forget about the question. Should i put this in a separate answer?