开发者

Android : How to handle properly a problem (activities/service) AssetManager

开发者 https://www.devze.com 2023-03-12 22:31 出处:网络
I\'ll try to be clear and brief: I\'d like to have an entity handling questions/answers in my game application.

I'll try to be clear and brief: I'd like to have an entity handling questions/answers in my game application. For this, I need to access to the assets folder (to browse within ressource files)

I need my handler to be accessible from different activities.

My problem is that a "normal" class can't do AssetManager mngr=getAssets();

So for the moment I have several constructor for this java class (one per activity call), so my class can retrieve ressources from wherever I am (by going through the activity method)

I know it's not the way it's supposed to be. I looked up services, but I don't find the way to have a "global" service from where I can ca开发者_运维百科ll function from whatever activity I'm in.

If someone understands my problem and can give me some advice about how to reorganize my app, it would be really appreciated!

Thank you very much


Methods, which are called in Activity, could be also called though Context class. So, you could pass activity Context(or better application Context) to your class:

class MyClass{
  MyClass(Context context){
     AssetManager mngr=context.getAssets();  
  }
}

In activity:

MyClass myClass = new MyClass(this);
0

精彩评论

暂无评论...
验证码 换一张
取 消