I have on Service that must communicate with an Activity (MyActivity) through a BradcastReceiver. This BroadcastReceiver is declare intosame activity so :
private class MessaggiReceiver extends BroadcastReceiver {
public static final String ACTION_RELOAD = "it.android.dev.thecode.ACTION_RELOAD";
@Override
public void onReceive(Context arg0, Intent intent) {
if(intent.getAction().equals(ACTION_RELOAD)){
leggi_act; //Method of MyActivity
}
}
}
but how must declare into Manifest the brodcast contained within the MyActivity ? I used this code with it.android.dev.thecode.MyActivity.MessaggiReceiver
<receiver android:name="it.android.dev.thecode.MyActivity.MessaggiReceiver">
<intent-filter>
<action android:name="it.android.dev.thecode.ACTION_RELOAD"></action>
</intent-filter>
</receiver>
but is wrong then I used this code with it.android.dev.thecode.myactivity$MessaggiReceiver
<receiver android:name="it.android.dev.thecode.MyActivity$MessaggiReceiver">
<intent-filter>
<action android:name="it.android.dev.thecode.ACTION_RELOAD"></action>
</intent-filter>
</receiver>
Thanks
You don’t need to register a broadcast receiver in your manifest, instead register it by code in your activity’s onResume. Don’t forget to unregister in onPause to avoid any leaks.