Hello,
As the title suggest, i am trying to pass a Document between activities in android.
I tried to use Parcelable via Intent but i didn’t suceed.
Might someone be able to help ?
Regards
Hello,
As the title suggest, i am trying to pass a Document between activities in android.
I tried to use Parcelable via Intent but i didn’t suceed.
Might someone be able to help ?
Regards
Hey @heretyk,
Could you post some of your logs and code snippets of where you implemented the Parcelable
class with the Intent
instance interactions for discussion.
Thanks,
William
Hi @sweetiewill,
Finally, i have been re-thinking my code, and i realized that just passing the id of the doc to my child activity, and retrieving the Document with that id might be a better way to do it …in terms of operations/ressources (mem,cpu…) usages.
Do you confirm ?
For information, here is what i tried before :
From parent Activity (in a fragment with ListView) :
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (null != mListener) {
// Get Document "behind" the clicked item
Document clickedDoc = (Document) mListView.getItemAtPosition(position);
Intent i = new Intent(getActivity(), ViewProfileActivity.class);
i.putExtra("clickedDoc",new ParcelableDocument(MainActivity.database,clickedDoc.getId()));
startActivity(i);
}
}
In ViewProfileActivity (child activity) :
protected Bitmap picture1;
protected ParcelableDocument documentParcel;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = getIntent();
Bundle data = intent.getExtras();
documentParcel = data.getParcelable("clickedDoc");
setContentView(R.layout.activity_view_profile); // Load the layout
createToolbar();
viewDocument();
}
ParcelableDocument Class
public class ParcelableDocument extends Document implements Parcelable {
private int mData;
/**
* Constructor
*
* @param database The document's owning database
* @param documentId The document's ID
* @exclude
*/
public ParcelableDocument(Database database, String documentId) {
super(database, documentId);
}
public int describeContents() {
return 0;
}
public void writeToParcel(Parcel out, int flags) {
out.writeInt(mData);
}
public static final Parcelable.Creator<ParcelableDocument> CREATOR
= new Parcelable.Creator<ParcelableDocument>() {
@Override
public ParcelableDocument createFromParcel(Parcel source) {
return null;
}
public ParcelableDocument[] newArray(int size) {
return new ParcelableDocument[size];
}
};
}
Best regards,