Andrea Baccega Andrea Baccega - 1 year ago 111
Android Question

Static way to get 'Context' on Android?

Is there a way to get the current 'Context' instance by using a static method?

I'm looking for that way because I hate saving the 'Context' instance each time it changes.

Answer Source

Do this:

In the Android Manifest file, declare the following.

<application android:name="">


Then write the class:

public class MyApplication extends Application {

    private static Context context;

    public void onCreate() {
        MyApplication.context = getApplicationContext();

    public static Context getAppContext() {
        return MyApplication.context;

Now everywhere call MyApplication.getAppContext() to get your application context statically.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download