Android DataBinding where to get context?
Also you can do something like this in your view using the current view context as parameter. … android:text=”@{yourModelHere.yourModelMethodHere(context)}” …
Also you can do something like this in your view using the current view context as parameter. … android:text=”@{yourModelHere.yourModelMethodHere(context)}” …
It is worth reviewing the sources that show that a Context instance (be it an Activity or an Application instance) share the same static map HashMap<String, SharedPreferencesImpl>. So whenever you request an instance of SharedPreferences by the same name via Context.getSharedPreferences(name, mode) you get the same instance since it first checks if the map already … Read more
A Context is a handle to the system; it provides services like resolving resources, obtaining access to databases and preferences, and so on. It is an “interface” that allows access to application specific resources and class and information about application environment. Your activities and services also extend Context to they inherit all those methods to … Read more
You can reference an outer context when you define your DialogInterface.OnClickListener as an anonymous class. If you’re in an activity you can use MyActivity.this as the context. Edit – since your Activity is implementing DialogInterface.OnClickListener, you should be able to just use this as the context.
Replace context with getActivity(). The ApplicationContext should not be used for tasks such as creating Dialogs. As you are in a fragment you can instead get the Activity-Context simply by calling the Fragments getActivity() method.
If you already have a valid context, just use this: Activity activity = (Activity) context;
For example you can find any textView: TextView textView = (TextView) ((Activity) context).findViewById(R.id.textView1);
There is one more way, add application class in your library project: /** * Base class for those who need to maintain global application state. */ public class LibApp extends Application { /** Instance of the current application. */ private static LibApp instance; /** * Constructor. */ public LibApp() { instance = this; } /** … Read more
You need to do following things. when you want to use AsyncTask, extend that in other class say MyCustomTask. in constructor of new class, pass Context Example public class MyCustomTask extends AsyncTask<Void, Void, Long> { private Context mContext; public MyCustomTask (Context context){ mContext = context; } //other methods like onPreExecute etc. protected void onPostExecute(Long result) … Read more
public abstract void onReceive(Context context, Intent intent) onReceive gives you the context. What more do you want?