背景从Honeycomb(API11)开始,Android具有允许广播接收器以异步方式运行的功能,在假定它可以终止其进程之前提供大约10秒,使用称为“goAsync”的方法:ThiscanbecalledbyanapplicationinonReceive(Context,Intent)toallowittokeepthebroadcastactiveafterreturningfromthatfunction.Thisdoesnotchangetheexpectationofbeingrelativelyresponsivetothebroadcast(finishingitwith
背景从Honeycomb(API11)开始,Android具有允许广播接收器以异步方式运行的功能,在假定它可以终止其进程之前提供大约10秒,使用称为“goAsync”的方法:ThiscanbecalledbyanapplicationinonReceive(Context,Intent)toallowittokeepthebroadcastactiveafterreturningfromthatfunction.Thisdoesnotchangetheexpectationofbeingrelativelyresponsivetothebroadcast(finishingitwith
我有一个BroadcastReceiver,我想在其中执行一些脱离UI线程的工作。根据exampleintheBroadcastReceiverdocumentation,我首先调用goAsync(),它返回一个PendingResult,然后在我的非UI线程中调用PendingResult.finish()。但是,我得到一个NullPointerException,因为goAsync()返回null。我做错了什么?这是一个复制该行为的简单示例。我使用了targetSdkVersion27和minSdkVersion23:packagecom.example.broadcastrece