What is the role of context? It is used in many places. Here, android123 provides a simple explanation for these new beginners:
Context literally indicates the context, which is located in the android. content. in context, this type is actually long, similar to the handle in Win32. Many methods need to use context to identify the caller's instance. For example, the first parameter of toast is context, generally, we directly use this instead of activity, which indicates that the caller's instance is activity. When a method such as onclick (view) of a button is used, an error is reported when this is used, so we may use activityname. this is mainly because the classes that implement context mainly have several models unique to Android, such as activity, service, and broadcastreceiver.
Generally, the methods that require the context instance mainly include various service implementation classes. For example, when the sensormanager is instantiated, The getsystemservice (string) method must be executed by the context instance, there are also some private file system I/O such as openfileinput and the commonly used toast maketext method.