通过捆绑的另一个活动传递价值,并得到其价值 [英] Passing values through bundle and get its value on another activity
本文介绍了通过捆绑的另一个活动传递价值,并得到其价值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我通过捆绑的价值,你可以在我的code见。
现在,我想在另一个活动的价值的onCreate()
。我试了一下,以获得它的价值,但它显示NullPointerException异常。
请帮我解决这个问题。
捆绑包=新包();
字符串URL =http://www.google.com;
bundle.putString(URL,网址);
意图myIntent =新的意图(背景下,NotificationService.class);
myIntent.putExtras(包);
context.startService(myIntent);
获取价值code:
如果(!getIntent()。getExtras()的getString(URL)。包括(空)){
// 做一点事
}
解决方案
这应该是过程。
创建一个新的意图借助捆绑,并开始活动。
意向书我=新的意图(背景下,ActivityName.Class);
i.putExtra(钥匙,MyString的);
startActivity(ⅰ);
取包这样的新的活动里面的onCreate
捆绑额外= getIntent()getExtras()。
字符串值;
如果(临时演员!= NULL){
值= extras.getString(钥匙);
}
I am passing value through Bundle as you can see in my code.
Now, I want its value in another activity onCreate()
. I tried it to get its value but it is showing nullpointerexception.
Please help me solve the problem.
Bundle bundle = new Bundle();
String url = "http://www.google.com";
bundle.putString("url", url);
Intent myIntent = new Intent(context, NotificationService.class);
myIntent.putExtras(bundle);
context.startService(myIntent);
Get Value code :
if (!getIntent().getExtras().getString("url").contains(null)) {
// Do something
}
解决方案
This should be the procedure.
Create a new Intent with bundle and start the activity.
Intent i = new Intent(context, ActivityName.Class);
i.putExtra("key", mystring);
startActivity(i);
Take the bundle like this in new Activity inside onCreate
Bundle extras = getIntent().getExtras();
String value;
if (extras != null) {
value = extras.getString("key");
}
这篇关于通过捆绑的另一个活动传递价值,并得到其价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文