Reputation: 4370
I received an ANR log for my BroadcastReceiver, but why? onReceive()
is just starting an IntentService
, which should probably take some milliseconds, right? And the IntenteService
's onHandleIntent()
is called in the background?
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);
}
First part of the log:
----- pid 4006 at 2015-07-02 15:51:35 -----
JNI: CheckJNI is off; workarounds are off; pins=0; globals=496
DALVIK THREADS: (mutexes: tll=0 tsl=0 tscl=0 ghl=0)
"main" prio=5 tid=1 WAIT | group="main" 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) - waiting on <0x4185ef70> (a java.lang.VMThread) held by tid=1 (main) at java.lang.Thread.parkFor(Thread.java:1205) at 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) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireQueued(AbstractQueuedSynchronizer.java:846) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquire(AbstractQueuedSynchronizer.java:1175) at java.util.concurrent.locks.ReentrantLock$NonfairSync.lock(ReentrantLock.java:180) at java.util.concurrent.locks.ReentrantLock.lock(ReentrantLock.java:256) at 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(Native Method)
I've registered my receiver via 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>
Upvotes: 3
Views: 9318
Reputation: 7474
Context#registerReceiver(BroadcastReceiver, IntentFilter)
any application may send broadcasts to that registered receiver
you can control who can send broadcasts to it through permissions
when you publish a receiver in your application's manifest and specify intent-filters for it, any other application can send broadcasts to it regardless of the filters you specify.
to prevent others from sending to it, make it unavailable to them with android:exported="false"
.
in your case problem is in :
uncaughtException in com.google.android.gms.analytics
(ANR is probably caused by deadlock - main is waiting for Thread:1205)
SOLUTION:
filter onReceive() for not intended broadcasts,
try catch exception
if u cant try Ovverride some methods
Upvotes: 1