Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing File with intent, how do i retrieve it

Here is what I am passing. pictureFile is a File

Intent intent = new Intent (context, ShowPicActivity.class);
intent.putExtra("picture", pictureFile);

In the next activity which one of the getters do I use to get it?

Intent intent = getIntent(); .....?

like image 670
dsuma Avatar asked Oct 16 '13 07:10

dsuma


2 Answers

File implements serializable ( first thing to check to send an object through an intent. ) ( source )

so you can do it, just cast the resulting object to File like this :

File pictureFile = (File)getIntent.getExtras().get("picture");

It should be fine. (it use the getter for 'object' which needs a serializable object and return it. The cast should be enough.)

like image 56
Guian Avatar answered Sep 19 '22 17:09

Guian


Try the following:

YourPictureClass picture = (YourPictureClass)getIntent().getExtras().get("picture");

By calling getExtras() in your Intent you get an instance of Bundle.
With the normal get() in class Bundle you can read every Object you pass to the calling Intent. The only thing you have to do is to parse it back to the class your object is an instance of.  

like image 37
Obl Tobl Avatar answered Sep 18 '22 17:09

Obl Tobl