Differences between this, getApplicationContext (), and getApplication () in Android, getapplication

Source: Internet
Author: User

Differences between this, getApplicationContext (), and getApplication () in Android, getapplication
This: indicates the current Activity, which represents the current Activity, in other words, Activity. this can be abbreviated as this in Activity.
GetApplicationContext (): the entire application lifecycle is destroyed only when the application is destroyed.
GetApplication (): share global data in andorid development;
During our normal development, we may sometimes need some global data to make all the activities and views in the application accessible. In this case, you may first think of defining a class and then creating many static members. However, andorid provides us with a solution for this situation: in Android, there is a class named Application, we can use getApplication () in the Activity to obtain it. It represents the class of our application. We can use it to obtain the topic of the current application and content in the resource file, A more flexible feature of this class is that it can be inherited by us to add our own Global attributes.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.