简体   繁体   English

在设备启动时将数据从android活动传递到广播接收器

[英]Passing data from android activity to broadcast receiver on device boot up

I always get bundle value null when I pass data from activity to broadcast receiver. 当我将数据从活动传递到广播接收器时,我总是将bundle值设置为null 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");

Your code in activity will never be called upon booting up. 处于活动状态的代码将永远不会在启动时被调用。 System invokes onReceive() with its own intent. 系统以自己的意图调用onReceive()。 You can check this by putting some logs in activity code - this log will not be printed in logcat. 您可以通过在活动代码中放置一些日志来进行检查-此日志不会在logcat中打印。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM