Android assets without context

Regarding the Android Assets manager, is it possible to get a file from assets without context? I read that I can initialize the File object with the file type "file: /// android_assets" and then get the file from there, but it says the file does not exist (Honeycomb).

What is the general workaround for this problem? There is no way to get context in the place where I need files from assets.

thanks

+6
source share
1 answer

To access the Context in which it is absent, you can extend the Application class and create a static link to the Context. Thus, you can access it from anywhere in the application:

public class MyApp extends Application { public static Context context; @Override public void onCreate() { super.onCreate(); context = getApplicationContext(); } } 
+4
source

Source: https://habr.com/ru/post/892208/


All Articles