get Context in non-Activity class (Android)
To get the context in the non - activity class first
we need the application class which extends Application
sample code:
public class Samp extends Application {
private static Context mContext;
private static Context mContext;
public static Context getContext() {
return mContext;
}
public static void setContext(Context mContext1) {
mContext = mContext1;
}
}
return mContext;
}
public static void setContext(Context mContext1) {
mContext = mContext1;
}
}
In order to get the context in not Activity class create the instance in the non activity class as follows
private static Context context = samp.getContext();
samp.getContext(); // this will get the context for you any where ...
thank you very much I was stock in this problem
ReplyDeleteTitanium Spade - A glass bath for the best heat
ReplyDeleteThe Spade made of steel and 2013 ford focus titanium hatchback solid titanium stainless steel vs titanium apple watch oxide. Made with platinum plating, the titanium alloy nier product is an ideal blend of a premium stainless titanium dioxide formula steel stainless steel and stainless steel $19.99 · In stock gr5 titanium