I have a problem that I can't understand why it happens, I've been looking for more places before asking but I haven't found anything, here is the problem:
I create an Intent to send a broadcast as follows:
Intent intent = new Intent(contexto,BroadcastReciver.class);
intent.putExtra("key","texto"));
contexto.sendBroadcast(intent);
This causes the BroadcastReciver class to start and I go into the method onRecive()
and I do the following:
@Override
public void onReceive(Context context, Intent intent) {
String aux=intent.getStringExtra("key");
}
Well, when it gets there, that Intent that I receive has the Extras to null and I don't know why, I have verified that when creating the intent the data is not empty and everything is correct until I reach the BroadcastReciver class.
EDITED: In manifest.xml I have it declared as follows:
<receiver android:name=".utils.BroadcastReciver" />
utils is a package I have created myself.
I have managed to do it in a somewhat "sloppy" way and in my opinion it is not a solution.
I have done the following:
And in the onReceive():
This way, by passing the String as an action I can get it later and use it for my purpose.
The problem with this is that it would be using a method
intent.setAction()
that its function is not the one I am giving it, and another problem would be that it could only be passed a String data.That's why I say it's a "botch" and not a solution, but hey, for now it works for me and lets me continue with my development.