0

I have created one class that is extending Application class and using the static method to expose the contexts as follows. moreover i am using many util methods like checking internet connections e.c.t into this class.

Problem is i am not sure

  1. how safe is to use following method to expose the application level context
  2. would this create any memory leaks when i will use App.getAppContext() method

    public class App extends Application {        
    
    private static Context mContext;
    
    @Override
    public void onCreate() {
    super.onCreate();
    mContext = this.getApplicationContext();
    }
    
    public static Context getAppContext() {
    
    return mContext;
    }
    

    }

Hunt
  • 8,215
  • 28
  • 116
  • 256
  • 3
    Possible duplicate of [Using Application context everywhere?](http://stackoverflow.com/questions/987072/using-application-context-everywhere) – Bö macht Blau Nov 18 '16 at 10:05
  • according to that question `Context.getApplicationContext()` can be used but its not available – Hunt Nov 18 '16 at 10:18
  • Possible duplicate of [getApplication() vs. getApplicationContext()](http://stackoverflow.com/questions/5018545/getapplication-vs-getapplicationcontext) – Akshay Chordiya Nov 18 '16 at 10:35
  • It's safe to a certain degree, except `android:process=":remote"` makes a second process, which results in a second Application instance. – EpicPandaForce Nov 19 '16 at 12:44

0 Answers0