How can I get resource content from static context?

Asked 1 years ago, Updated 1 years ago, 127 views

I'd like to read the string in xml. I need a lot from the widget, so can I call getResource and get it without an activity object?

android java static const android-resources

2022-09-21 20:23

1 Answers

public class App extends Application{

    private static Context mContext;

    @Override
    public void onCreate() {
        super.onCreate();
        mContext = this;
    }

    public static Context getContext(){
        return mContext;
    }
}

If you do this, you can get context values at any time using the App.getContext() method. And App.getContext().You can get the value of getResource with getResource().


2022-09-21 20:23

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.