stumbled upon the code, when creating an intent, the
CONTEXT object is transmitted. Why is it needed, I do not understand? If you can, as simple as possible.
Answer 1, Authority 100%
context is an object that provides access to the basic functions of the application: access to resources, to the file system, challenge activity, etc.
Activity is a subclass
context , so in the code we can use it as
Name Nativity.This (eg
MainActivity.this ), or the shortened entry
This . Classes
Application et al. Also work with context.
Access to the context can be obtained in different ways. There are methods such as
getApplicationContext () ,
getContext () ,
getbasecontext () or
this , which was mentioned above If used in activity.
At first, it is not necessary to understand why it is needed. It is enough to remember the methods that allow you to get a context and use them if necessary, when some method or constructor will require the CONTEX object in its parameters.
In turn, Context has its own methods that allow access to resources and other objects.
getassets () GetResources () getPackagemanager () getstring () GetSharedprefsfile ()