您的位置:首页 > 其它

BroadcastReceiver里的context

2016-11-04 14:49 281 查看
官方文档对onReceive方法里context参数的解释是:The Context in which the receiver is running.

如果是静态注册的Broadcast,context.toString()输出为:android.app.ReceiverRestrictedContext@e5d8f65

如果是动态注册的Broadcast,context.toString()输出为:com.example.test.MainActivity@84dfef5

静态与动态注册的的Broadcast,context.getPackageName()输出都为:com.example.test

无论静态还是动态注册的Broadcast,都跑在广播所在app的进程。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: