What is the role of context?

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.