Pergunta

I always get bundle value null when I pass data from activity to broadcast receiver. My receiver will start on boot up.

This is the code in my activity class

Intent intent= new Intent();
intent.setAction("android.intent.action.BOOT_COMPLETED");
intent.putExtra("test", "test");    
sendBroadcast(intent);

This is the code in my receiver class:

String testValue = intent.getStringExtra("test");
Foi útil?

Solução

Your code in activity will never be called upon booting up. System invokes onReceive() with its own intent. You can check this by putting some logs in activity code - this log will not be printed in logcat.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top