最简单(也是正确的)方法是:
定义一个新类
public class MyApp extends Application { private static MyApp instance; public static MyApp getInstance() { return instance; } public static Context getContext(){ return instance; // or return instance.getApplicationContext(); } @Override public void onCreate() { instance = this; super.onCreate(); }}然后,在清单中需要将此类添加到“应用程序”选项卡的“名称”字段中。或编辑xml并放入
<application android:name="com.example.app.MyApp" android:icon="@drawable/icon" android:label="@string/app_name" ....... <activity ......
然后可以从任何地方打电话
MyApp.getContext();
希望能帮助到你



