如图,我在另一个类中调用PhoneReceiver类中的onReceive函数,但是不知道该给它传什么值。求大神!
Android怎么给onReceive()函数传参数
答案:6 悬赏:20
解决时间 2021-03-21 17:53
- 提问者网友:霸道ぁ小哥
- 2021-03-21 06:23
最佳答案
- 二级知识专家网友:瘾与深巷
- 2021-03-21 07:29
Android怎么给onReceive()函数传参数有几种解决办法
解决方案1:
该函数是系统回调函数,不是给你调用的,你需要调用sendBroadcast(Intent o)
解决方案2:
这是个广播接收器,用来接收广播的,可以通过intent来获取广播传过来的值
解决方案3:
解决方案4:
发送广播消息是通过Context.sendBroadcast(intent)
intent中附加要传递的值
解决方案1:
该函数是系统回调函数,不是给你调用的,你需要调用sendBroadcast(Intent o)
解决方案2:
这是个广播接收器,用来接收广播的,可以通过intent来获取广播传过来的值
解决方案3:
解决方案4:
发送广播消息是通过Context.sendBroadcast(intent)
intent中附加要传递的值
全部回答
- 1楼网友:旧事诱惑
- 2021-03-21 10:59
这个不适合你,回去种地吧,~~(╯﹏╰)b
- 2楼网友:堕落奶泡
- 2021-03-21 10:01
发送广播消息是通过Context.sendBroadcast(intent)
intent中附加要传递的值
- 3楼网友:心与口不同
- 2021-03-21 09:34
这是个广播接收器,用来接收广播的,可以通过intent来获取广播传过来的值
- 4楼网友:安稳不如野
- 2021-03-21 07:58
Android怎么给onReceive()函数传参数有几种解决办法
解决方案1:
该函数是系统回调函数,不是给你调用的,你需要调用sendBroadcast(Intent o)
解决方案2:
这是个广播接收器,用来接收广播的,可以通过intent来获取广播传过来的值
解决方案3:
发送广播消息是通过Context.sendBroadcast(intent)
intent中附加要传递的值,例如:
//使用Bundle传递参数到另一个Activity
BundleBtn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
//使用Bundle传递参数
Intent myIntent = new Intent();
Bundle bundle = new Bundle();
bundle.putString("info",myEditText.getText().toString());
myIntent.putExtras(bundle);
myIntent.setClass(MainActivity.this, Activity3Bundle.class);
startActivity(myIntent);
}
});
- 5楼网友:转身→时光静好
- 2021-03-21 07:40
一个broadcastreceiver 对象只有在被调用onreceive(context, intent)的才有效,当从该函数返回后,该对象就无效的了,结束生命周期。
因此从这个特征可以看出,在所调用的onreceive(context, intent)函数里,不能有过于耗时的操作,不能使用线程来执行。对于耗时的操作,应该在startservice中来完成。因为当得到其他异步操作所返回的结果时,broadcastreceiver 可能已经无效了。
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯