When exactly is the Context class used on Android? I went to the developer site and read it, but I don't understand it.
android android-context
Simply put, it's a class about the current state of an app or object. GetApplicationContext(), getContext(), getBaseContext(), or You can get context with this in the activity
Usually when you create a new object, such as View, adapter, or listener,
TextView tv = new TextView(getContext());
ListAdapter adapter = new SimpleCursorAdapter(getApplicationContext(), ...);
I write it like this.
When accessing Standard Common Resources such as LAYOUT_INFLATER_SERVICE and Shared Preferences
context.getSystemService(LAYOUT_INFLATER_SERVICE)
getApplicationContext().getSharedPreferences(*name*, *mode*);
I write it like this.
Also, content providers, broadcasts, intents
getApplicationContext().getContentResolver().query(uri, ...);
I write it like this
© 2024 OneMinuteCode. All rights reserved.