not able to get json passed into intent to another activity
I am using below code(in brief)
In Global class named as Utilities public static final String KEY = "MY_KEY";
//Pojo Class
ViewPojo mPojo;
//ActivityDemo
Intent intent = new Intent(this, MyActivity.class);
intent.putExtra(Utilities.KEY, new Gson().toJson(mPojo));
//MyActivity
pojoJson = getIntent().getStringExtra(Utilities.KEY);
mPojo = new Gson().fromJson(pojoJson, ViewPojo.class);
null is being returned, I am not clear how and why this is happening.
same is working in case of Bundle.
Any help is appreciated. Thanks in advance.
Instead of getting the stringExtra
from the intent you should get the extra's from the intent and form there get the string.
//MyActivity
Bundle extras = this.getIntent().getExtras();
pojoJson = extras.getString(Utilities.KEY);
mPojo = new Gson().fromJson(pojoJson, ViewPojo.class);
You could also use a Parcelable implementation to directly send the object through the intent instead of parsing it to JSON, see https://developer.android.com/reference/android/os/Parcelable.html for more information
Please specify null value return intent.
so use bundle
Bundle extras = intent.getExtras(); mPojo = new Gson().fromJson(extras.getString(Utilities.KEY), ViewPojo.class);
链接地址: http://www.djcxy.com/p/67988.html上一篇: ASP.NET MVC有条件验证
下一篇: 无法让JSON传递到另一个活动的意图