I am trying to generate a notification from a class, Utilities.java
, outside of the subclass of Context
. I've thought about providing a SingletonContext
class and have looked at posts ike this. I'd like to be able to return != null
Context
object since the notification can be generated at any given time because it is generated from a messageReceived()
callback.
What are there downsides to doing something like this:
public static Context c;
public class MainActivity extends Activity{
@Override
public void onStart()
super.onStart()
c = this.getApplicationContext();
}
//other method somewhere outside this class
public Context getContext(){
return MainActivity.c
}
I don't think it would be any different than putting this on the onCreate()
, however, it guarantees that the context is up to date when the activity starts.