How can I get a resource content from a static context?
问题 I want to read strings from an xml file before I do much of anything else like setText on widgets, so how can I do that without an activity object to call getResources() on? 回答1: Create a subclass of Application, for instance public class App extends Application { Set the android:name attribute of your <application> tag in the AndroidManifest.xml to point to your new class, e.g. android:name=".App" In the onCreate() method of your app instance, save your context (e.g. this ) to a static field