Reputation: 40156
How to access getResources in Android/kotlin module?
I have resource in resource folder for a module (non host) in Android. i need to call getResources from a non activity class. How can I do so? getApplicationContext is not available.
Upvotes: 0
Views: 264
Reputation: 167
Try this
public class Activity1 extends Activity {
public void onCreate(Bundle savedInstanceState) {
Myclass myClass = new Myclass(this);
}
}
Then you can use it in the constructor (or set it to an instance variable):
public class Myclass(){
private Context context;
public Myclass(Context current){
this.context = current;
}
public getResource(){
context.getResources().getXml(R.xml.resourcexml);
}
}
You can use interface also.
Upvotes: 1