
我有一些变量,我想传递给我的下一个活动,但我无法想办法做到这一点.
我的变量是:
JsONObject JsonObj = JsonArray.getJsONObject(i);String propID = JsonObj.getString("ID");Log.i("Value ID", propID);String propCity = JsonObj.getString("city");Log.i("Value city", propCity);String propPlace = JsonObj.getString("place");Log.i("Value place", propPlace);String propStation = JsonObj.getString("station");Log.i("Value station", propStation);我用来获取它们的代码是:
Bundle extras = new Bundle();extras.putString("ID", propID);extras.putString("city", propCity);extras.putString("place", propPlace);extras.putString("station", propStation);有人可以帮我这个吗?
解决方法:
您发布的代码是将它们写入Bundle,在Bundle中写入后使用.putExtras()将您的bundle放入Intent中.
intent.putExtras(bundle);例:
Intent intent = new Intent(this, YourClass.class);Bundle extras = new Bundle();extras.putString("ID", propID);extras.putString("city", propCity);extras.putString("place", propPlace);extras.putString("station", propStation);intent.putExtras(bundle);startActivity(intent);要在您的活动中阅读它,请使用getExtras()获取传递给它的Bundle,然后使用getString / getXXX.
无论如何,你可以避免创建Bundle并直接使用Intent的set方法,它们以相同的方式工作.
所以它会是:
Intent intent = new Intent(this, YourClass.class);intent.putExtra("ID", propID);intent.putExtra("city", propCity);intent.putExtra("place", propPlace);intent.putExtra("station", propStation);startActivity(intent); 总结 以上是内存溢出为你收集整理的android – 使用putExtra传递多个变量全部内容,希望文章能够帮你解决android – 使用putExtra传递多个变量所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)