这通常是我所拥有的:
class A extends Activity{
// On a click, starts service B.
}
class B extends IntentService{
C c = new C();
c.init();
}
class C {
public void init(){
// Read a file from the /raw directory.
}
}
在互联网上搜索时,我发现大量资源说要使用 getAssets。但是,我不能这样做,因为 C 没有扩展 Activity,因此看不到 A 的上下文。我想把它传下来,但我不能这样做,因为 A 在 Class 对象上而不是 B 本身上做了一个 startService。有没有办法简单地做到这一点(最好是获取 raw/ 文件夹的 URL),还是我必须做一些 Java 魔法才能让它工作?提前致谢。