Android 7.0新特性---删除三项广播

简述:

     Android N 除了提供诸多多窗口支持、活动通知、后台优化、消息传递服务和Vulkan 等新特性和功能外,还对系统和 API 行为做出了各种变更。本文介绍一下Android N 后台优化新特性。

Android官网官方文档:

   对于Android N后台的优化主要是关闭了三项系统广播:网络状态变更广播、拍照广播以及录像广播。接下来我们看看Android官方给出的说明:

    Background processes can be memory- and battery-intensive. For example, an implicit broadcast may start many background processes that have registered to listen for it, even if those processes may not do much work. This can have a substantial impact on both device performance and user experience.

To alleviate this issue, Android N applies the following restrictions:
    Apps targeting the Preview do not receive CONNECTIVITY_ACTION broadcasts if they register to receive them in their manifest. Apps that are running can still listen for CONNECTIVITY_CHANGE on their main thread by registering a BroadcastReceiver with Context.registerReceiver().
    Apps cannot send or receive ACTION_NEW_PICTURE or ACTION_NEW_VIDEO broadcasts. This optimization affects all apps, not only those targeting the Preview.
If your app uses any of these intents, you should remove dependencies on them as soon as possible so that you can target Android N devices properly. The Android framework provides several solutions to mitigate the need for these implicit broadcasts. For example, JobScheduler and GcmNetworkManager provide robust mechanisms to schedule network operations when specified conditions, such as a connection to an unmetered network, are met. You can now also use JobScheduler to react to changes to content providers. JobInfo objects encapsulate the parameters that JobScheduler uses to schedule your job. When the conditions of the job are met, the system executes this job on your app's JobService.

大致意思:

    Android N 删除了三项隐式广播,以帮助优化内存使用和电量消耗。 此项变更很有必要,比如说网络变化的广播(CONNECTIVITY_CHANGE),当网络发生变化时所有注册了隐式监听网络变化的app都会被启动。删除这些广播可以显著提升设备性能和用户体验。同样地,拍照广播和录视频广播(ACTION_NEW_PICTURE or ACTION_NEW_VIDEO)也会出现上述情况。

   为缓解这些问题,Android N 采取了以下优化措施:

        ① 在Android N平台下即使在Manifest.xml清单文件中注册了 CONNECTIVITY_ACTION广播,在网络发生变化时也不会接收到任何的信息。但是正在前台运行的应用程序如果在主线程中通过Context.registerReceiver()动态注册了CONNECTIVITY_ACTION广播,该应用程序仍然可以接收到该广播。(注:这样开发者就可以根据不同的网络状态加载相应的页面信息了,从而提高用户体验)。

        ② 应用程序无法发送或接收 ACTION_NEW_PICTURE(拍照) 或 ACTION_NEW_VIDEO(录像) 广播。此项优化会影响所有应用,而不仅仅是面向 Android N 的应用。

    如果您的应用使用任何上述广播,为了适配 Android N 设备请您尽快解除它们之间的依赖关系。 Android 框架提供多个解决方案来缓解对这些隐式广播的需求。比如,为了在特定的网络条件下执行特定的网络操作,Android提供了JobScheduler 和 GcmNetworkManager。

  


  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值