質問

I have Activity A, Activity B, and a static class in the same application. The scenario is as follows (it's simplified here; it makes more sense in my software):

  1. (in Activity A) mAppctx = this.getApplicationContext();
  2. (in Activity A) StaticClass.appctx = mAppctx;
  3. Activity B is spawned
  4. Assume that Activity A is destroyed by the system while Activity B is running
  5. Activity B does the following (pseudo-code): ..... = StaticClass.appctx.getResources().openRawResource(...);

Is this correct?

Since an application Context belongs to the Application (i.e. to the process), and not to the Activity, I suppose it's correct, and APK resources can be accessed in this way from the static class without any problem. (I know that Activity B could actually ask getApplicationContext() on his own, but the above question is intentionally different.)

役に立ちましたか?

解決

Yes, it is correct as both activity and aplication context access same resources.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top