Wednesday, July 13, 2011

Broadcast receiver problem

Today I saw a weird bug. I had a broadcast receiver in one app's AndroidManifest.xml


<receiver android:name=".MyReceiver">


<intent-filter>


<action android:name="com.my.intent.update" />


</intent-filter>


</receiver>




and another app sent broadcast with the intent the first app had to handle.




Intent intent = new Intent("com.my.intent.update");


sendBroadcast(intent);




The problem was it never did. I spent some time and asked my co-worker to look at it with me. While looking I found the problem (pair programming works after all). I had an activity in the same manifest file that had a receiver that handled the same intent!





<activity android:label="Test" android:name=".HomeActivity"


android:launchMode="singleTask" android:configChanges="orientation">


<intent-filter>


<action android:name="com.my.intent.update" />


</intent-filter>


</activity>




I don't know why it was there but it made receiver never handle the intent.



No comments: