Getapplicationcontext (), Getbasecontext (), Getapplication (), GetParent ()

Source: Internet
Author: User

Getapplicationcontext () Application context is associated with the applicaition and would always be the same throughout the life cycle.

Getbasecontext () should not being used just use Context instead of it which was associated with the activity and Coul D possible be destroyed if the activity is destroyed.

getapplication () is available to Activity and Services only. Although in current Android Activity and Service implementations, getapplication () and Getapplicationcontext () return the same object, there is no guarantee that this would always be the case (for example, In a specific vendor implementation).  So if you want the application class you registered in the Manifest and you should never callGetapplicationcontext () and cast it to your application, because it may is the the application instance (which you obviously experienced with the Test framework).

getParent () returns object of the activity if the current view was a child. In other words returns the activity object hosting, the child view, called within the child.

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.