Detailed explanation of context usage in Android

Detailed explanation of context usage in Android

Summary:

Context literally means context, which is located in android.content.context of framework package. In fact, this class is of long type, similar to the handle handle in Win32. Many methods need context to identify the caller's instance: for example, the first parameter of toast is context. Generally, in activity, we directly use this instead, and the instance representing the caller is activity. When we use a button's onclick (view view) and other methods, we will report an error when we use this, so we may use activityname.this to solve it, The main reason is that the classes that implement context mainly include several models unique to Android, activity and service.

Context provides an interface for global information about the application environment. It is an abstract class whose execution is provided by the Android system. It allows the acquisition of resources and types characterized by applications. Start application level operations at the same time, such as starting activities, broadcasting and receiving intents.

The following describes some get methods of context. Through these get methods, you can obtain the global information of the application environment:

There are many useful methods, which are not listed one by one. Please refer to the documentation for details. Anyway, context is very useful.

If you have any questions, please leave a message or go to the community of this site for communication and discussion. Thank you for reading. I hope it can help you. Thank you for your support to this site!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>