I need to pass my data object within the intent so that called activity can use that. But finding no method to add those to the intent.
Can any one please put light in this
Thanks
I need to pass my data object within the intent so that called activity can use that. But finding no method to add those to the intent.
Can any one please put light in this
Thanks
You will need to make your data object parcelable and send it within the intent.
Check the link below. Hope it will help you :)
http://prasanta-paul.blogspot.com/2010/06/android-parcelable-example.html
You can attach data to an intent using putExtras
String dataToPass = "The next activity needs this sentence."; ... Intent intent = new Intent(this, NextActivity.class); intent.putExtras("KeyToAccessData", dataToPass); startActivity(intent);
And to retreive it from the intent
String dataToCollect; ... Intent intent = getIntent(); dataToCollect = intent.getStringExtra("KeyToAccessData");
Just make your custom object implement Serializable
. Then you can use intent.putExtra("package.name.Name", <your-serializable-object>)
. In the second activity you read it using getIntent().getSerializableExtra("package.name.Name")
You could try creating a method in your custom object class to create an object from a json string and also create a method to convert the object to a json string. This way, you can pass the object as a string and rebuild it when you get to string from the other intent.
String objectJsonString = '["name":"objName", "value":"somevalue"]'; ... Intent intent = new Intent(this.getApplicationContext(), OtherActivity.class); intent.putExtras("KeyToAccessData", objectJsonString); sartActivity(intent);
Then you recreate it in the new activity
Intent i = getIntent(); CustomObj obj = CustomObj.makeFromJsonString(i.getStringExtra("KeyToAccessData"));