我收到了我的BroadcastReceiver的ANR日志,但为什么? onReceive()
刚刚开始IntentService
,这可能需要几毫秒,对吗? IntenteService
' s onHandleIntent()
在后台调用?
public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Explicitly specify that GcmIntentService will handle the intent.
ComponentName comp = new ComponentName(context.getPackageName(), GcmIntentService.class.getName());
// Start the service, keeping the device awake while it is launching.
startWakefulService(context, (intent.setComponent(comp)));
}
}
// GcmIntentService
@Override
protected void onHandleIntent(Intent intent) {
// executing db related stuff
// Release the wake lock provided by the WakefulBroadcastReceiver.
WakefulBroadcastReceiver.completeWakefulIntent(intent);
}
日志的第一部分:
----- pid 4006 at 2015-07-02 15:51:35 -----
JNI:CheckJNI已关闭;解决方法已关闭;销= 0;全局= 496 DALVIK THREADS :(互斥:tll = 0 tsl = 0 tscl = 0 ghl = 0)
"主" prio = 5 tid = 1 WAIT |基团="主" sCount = 1 dsCount = 0 obj = 0x4185eea0 self = 0x41750030 | sysTid = 4006 nice = -11 sched = 0/0 cgrp = apps handle = 1073869140 | state = S schedstat =(0 0 0)utm = 10745 stm = 2490 core = 0 at java.lang.Object.wait(Native Method) - 等待< 0x4185ef70> (java.lang.VMThread)由tid = 1(main)在java.lang.Thread.parkFor(Thread.java:1205)中保存 sun.misc.Unsafe.park(Unsafe.java:325)at java.util.concurrent.locks.LockSupport.park(LockSupport.java:157)at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:813) 在 java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:846) 在 java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1175) 在 java.util.concurrent.locks.ReentrantLock中的$ NonfairSync.lock(ReentrantLock.java:180) 在 java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:256) 在com.google.android.gms.analytics.bn.e((null): - 1)at com.google.android.gms.analytics.c.f((null): - 1)at com.google.android.gms.analytics.b.uncaughtException((null): - 1)at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:693)at java.lang.ThreadGroup.uncaughtException(ThreadGroup.java:690)at dalvik.system.NativeStart.main(原生方法)
我通过manifest.xml注册了我的接收器:
<receiver
android:name="receiver.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="de.cwalz.receiver" />
</intent-filter>
</receiver>
答案 0 :(得分:0)
Context #registerReceiver(BroadcastReceiver,IntentFilter)
您可以控制谁可以通过权限向其发送广播
当您在应用程序的清单中发布接收器并为其指定intent-filters时,任何其他应用程序都可以向其发送广播您指定的过滤器。
android:exported="false"
在您的情况下问题出在:
com.google.android.gms.analytics 中的uncaughtException
(ANR可能是由死锁引起的 - 主要是等待线程:1205)
解决方案:
针对非预期广播过滤onReceive(),
尝试捕获异常
如果你不能尝试Ovverride的一些方法