Question

I have an activity in which I have a broadcast receiver (br). If I register the br programmatically the receiver is registered and works great.

However, if I register the receiver in the manifest I receive a java.lang.ClassNotFoundException.

<receiver             
        android:name=".MyActivity.UpdateUIClass"
        android:exported="false"
        >
        <intent-filter>
            <action android:name="com.mydomain.main.FILTER_UPDATE_UI" />
            <category android:name="android.intent.category.DEFAULT" />                
        </intent-filter>
    </receiver>

Please advise

Was it helpful?

Solution

If UpdateUIClass is an internal class of MyActivity then you need to refer to it this way android:name=".MyActivity$UpdateUIClass"

This is the way you do it in a layout XML. Not sure if this will work for the manifest but give it a go and see if it works.

Edit

This is not possible unless the inner class is static as the manifest marshals all objects at load and not on demand. The class hosting the sub-class does not exist at the time the receiver is being resolved.

Related question: Is it possible to define a broadcast receiver as an inner class in manifest file?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top