Passing object between activity

General topics about the Android-Platform itself.
Coding issues please to the subforum right below.

Passing object between activity

Postby mac_fly » Mon May 12, 2008 5:57 pm

Hello,

My first activity list file wich are store in the phone and the second activity display all picture file.

The second activity need a list of file(
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. File[] myfile
Parsed in 0.029 seconds, using GeSHi 1.0.8.4
). How can i start the second activity with the argument myfile.

Thanks.
mac_fly
Freshman
Freshman
 
Posts: 2
Joined: Mon May 12, 2008 5:48 pm

Top

Postby tum0rc0re » Mon May 12, 2008 8:50 pm

Send one parameter:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Intent newIntent = new Intent(this, SecondActivity.class);
  2.  
  3. newIntent.putExtra(“file”, filename);
  4.  
  5. startSubActivity(newIntent, 0);
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


Get this parameter:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. Bundle extras = getIntent().getExtras();
  3.  
  4. if (extras != null) {
  5.  
  6.    String myfilename = extras.getString(“file”);
  7.  
  8. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


But I don't know how send total array as in your case
JQ Soft web page:
[b][url=http://jqsoft.ru/]http://jqsoft.ru/[/url][/b]
My proffesional blog: [b][url=http://maximyudin.blogspot.com]http://maximyudin.blogspot.com[/url][/b]
Facebook: [b][url=http://www.facebook.com/maxim.yudin]http://www.facebook.com/maxim.yudin[/url][/b]
User avatar
tum0rc0re
Senior Developer
Senior Developer
 
Posts: 158
Joined: Sun Nov 25, 2007 7:15 am
Location: Moscow, Russia

Postby mac_fly » Tue May 13, 2008 9:57 am

Hello,

I have already try your solution and i don't want to get a string but an object of type File or FILE[] so i try that :
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         Bundle extras = getIntent().getExtras();
  3.  
  4.         if (extras != null) {
  5.  
  6.            myfile = (File[])extras.get("file");
  7.  
  8.         }
  9.  
  10.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


and i have an exception about the cast.

Anybody know how to pass object between activity ?
mac_fly
Freshman
Freshman
 
Posts: 2
Joined: Mon May 12, 2008 5:48 pm

Postby bavarol » Thu May 29, 2008 10:29 am

Hi mac_fly,
I have the same problem, I have tried this:

In the invoking Activity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.        
  2.  
  3.         Intent intent = new Intent(Class1.this, Class2.class);
  4.  
  5.         intent.putExtra("object", obj);
  6.  
  7.         startSubActivity(intent, 0);
  8.  
  9.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4


And then in the invoked Activity
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.         Bundle bundle = this.getIntent().getExtras();
  3.  
  4.         if ( bundle != null ) {
  5.  
  6.                 Object obj = bundle.get("object");  // It comes here an error <img src="http://www.anddev.org/images/smilies/sad.png" alt=":(" title="Sad" />
  7.  
  8.         }
  9.  
  10.  
Parsed in 0.037 seconds, using GeSHi 1.0.8.4


But I get an error in the invoked Activity:
Code: Select all
The Methode get(String) is undefined for the Type Bundle


Kind Regards

Bavarol

Ps:I have the SDK m3rc22a
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Re: Passing object between activity

Postby libertino » Thu May 29, 2008 6:51 pm

mac_fly wrote:Hello,

My first activity list file wich are store in the phone and the second activity display all picture file.

The second activity need a list of file(
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. File[] myfile
Parsed in 0.036 seconds, using GeSHi 1.0.8.4
). How can i start the second activity with the argument myfile.

Thanks.


I would suggest using local service, as I do in my application
libertino
Junior Developer
Junior Developer
 
Posts: 12
Joined: Sun May 18, 2008 3:36 pm

Postby bavarol » Fri May 30, 2008 12:00 pm

Hi,
you don't need services, you should see how it's implemented the class of your object, i.e. if you'd want to pass a Bitmap, then you should look at the interface, it implements, in this case is Parcelable, in other cases Serializable and there are methods in Bundle to put a Parcelable and a Serializable Object different to primitive Types like putString, putLong, etc..

I must develop under m3rc22a cause requisites of my Project but if you develop under m5, I can tell you, you can use the method put...(...) and get(String), which delivers an Object, you just need a Casting of this call.

I hope, I could help you.

Regards
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Top

Postby Jesmiatka » Fri May 30, 2008 12:47 pm

I am not sure, but I think passing objects in m5 doesn't work either..
At least the Serializable I tried some time ago didn't work..

Greetz,
Mike
Jesmiatka
Senior Developer
Senior Developer
 
Posts: 164
Joined: Mon Feb 04, 2008 3:37 pm
Location: Netherlands

Postby bavarol » Fri May 30, 2008 2:32 pm

I have done this with a Bitmap Jesmiatka and it worked with Parcelable, I don't know if it work with Serializable :( I have not tried, my SDK is m3rc22a

Cheers
bavarol
Experienced Developer
Experienced Developer
 
Posts: 52
Joined: Mon Dec 10, 2007 9:19 pm

Top

Return to General

Who is online

Users browsing this forum: No registered users and 2 guests