从活动传递参数给的BroadcastReceiver [英] Passing Parameters from An Activity to BroadcastReceiver
本文介绍了从活动传递参数给的BroadcastReceiver的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿,我一直在试图传递字符串数组从我的活动广播接收器,但它总是给我在广播空接收我已经尝试过以2-3的方式。
// code在接收器
串stringText = intent.getExtras()的getString(string_text);
// code的活动
意图I =新的意向书(android.intent.action.PHONE_STATE);
i.putExtra(string_text,ABC);
sendBroadcast(ⅰ);
但接收端stringText总是空。我已经尝试过以另一种方式,但没有运气
字符串文本=(字符串)intent.getSerializableExtra(string_text);
但到目前为止没有运气谁能帮助我解决这个问题?
解决方案
公共类GlobalVariable扩展应用{
私有String []变种;
公众的String [] getVar(){
回归VAR;
}
公共无效SETVAR(字符串[] VAR){
this.var = VAR;
}
}
和我的活动称之为
GlobalVariable appState =((GlobalVariable)this.activity.getApplication());
appState.getVar()
以上的code线检索类似的方式来设置
Hey I have been trying to pass an array of string from my activity to broadcast receiver but it always give me null at broadcast receive i have tried it in 2-3 ways.
// Code in Receiver
String stringText= intent.getExtras().getString("string_text");
//Code in Activity
Intent i = new Intent("android.intent.action.PHONE_STATE");
i.putExtra("string_text", "abc");
sendBroadcast(i);
but at receiver end stringText always come null. I have tried it in another way but no luck
String text= (String)intent.getSerializableExtra("string_text");
But till now no luck can anyone help me with this issue?
解决方案
public class GlobalVariable extends Application {
private String[] var;
public String[] getVar(){
return var;
}
public void setVar(String[] var){
this.var= var;
}
}
And called it in my activity
GlobalVariable appState = ((GlobalVariable) this.activity.getApplication());
appState.getVar()
above line of code to retrieve similar way to set
这篇关于从活动传递参数给的BroadcastReceiver的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文