博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
getApplicationContext()、getBasecontext()、getApplication() 、getParent()
阅读量:5248 次
发布时间:2019-06-14

本文共 1082 字,大约阅读时间需要 3 分钟。

getApplicationContext() Application context is associated with the Applicaition and will always be the same throughout the life cycle.

getBasecontext() should not be used just use Context instead of it which is associated with the activity and could possible be destroyed when 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 will always be the case (for example, in a specific vendor implementation). So if you want the Application class you registered in the Manifest, you should never callgetApplicationContext() and cast it to your application, because it may not be the application instance (which you obviously experienced with the test framework).

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

转载于:https://www.cnblogs.com/leamiko/p/3748256.html

你可能感兴趣的文章
给我们的Empty Object加个图标
查看>>
深入理解Java中的String
查看>>
Centos7安装并配置mysql5.6完美教程
查看>>
iOS 锁屏判断
查看>>
NFC身份证识别(二)
查看>>
转载--Typecho install.php 反序列化导致任意代码执行
查看>>
dsoframer组件详细使用(aspx.net)
查看>>
CodeForces 706C Hard problem
查看>>
【VMware vSphere】vSphere Data Protection简介
查看>>
javascript 模拟java 实现继承的5种方式
查看>>
软件工程课程设计团队项目总结与项目报告
查看>>
Min_25 筛 学习笔记
查看>>
微信小程序购物商城系统开发系列-目录结构
查看>>
人际交往能力:远比你想象的重要
查看>>
node起步
查看>>
SharedPreferences详解
查看>>
Agc011_C Squared Graph
查看>>
虚拟机性能监控与故障处理工具
查看>>
Codeforces Round #226 (Div. 2)C. Bear and Prime Numbers
查看>>
29.Divide Two Integers
查看>>