Passing main activity instance to subactivity

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

Passing main activity instance to subactivity

Postby Katharnavas » Fri Jan 18, 2008 2:20 pm

Hi,
1)How to pass the instance of the main activity to the subactivity so that public methods in the main activity can be called from the subactivity.

2) How to call a common subactivity from more than one activity class and how can we get the information that which activity calls that subactivity.

Any suggestions please...
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Top

Postby plusminus » Fri Jan 18, 2008 7:11 pm

Hello Katharnavas,

have a look at :src: this post.

To retrieve the name of the calling Activity do the following within onCreate():
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         ComponentName cn = getCallingActivity();
Parsed in 0.030 seconds, using GeSHi 1.0.8.4


Regards,
plusminus
Last edited by plusminus on Thu Jan 24, 2008 4:49 pm, edited 1 time in total.
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Katharnavas » Thu Jan 24, 2008 2:27 pm

How to return a vector from the subactivity to the main activity. With Bundle we can be able to send only primitive datatypes such as integer or string. But is it possible to return a vector.
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Postby plusminus » Thu Jan 24, 2008 4:40 pm

Hello Katharnavas,

this issue should helo you further :arrow: Passing and Recieveing Values between Activities.

Regards,
plusminus

[Edit] I see you found it already [/Edit]
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Postby Katharnavas » Fri Jan 25, 2008 5:14 am

plusminus wrote:Hello Katharnavas,

this issue should helo you further :arrow: Passing and Recieveing Values between Activities.

Regards,
plusminus

[Edit] I see you found it already [/Edit]


Hi
I could not understand , can you explain me the possibility.
Katharnavas
Senior Developer
Senior Developer
 
Posts: 100
Joined: Tue Dec 04, 2007 5:57 am
Location: India

Postby plusminus » Fri Jan 25, 2008 4:04 pm

Hello Katharnavas,

Ishatar suggested this:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. HashMap meMap=new HashMap();
  2. meMap.put("mystream",myStream);
  3. Intent myIntent.putExtra("memap",meMap);
  4.  
  5. Intent getIntent=getIntent();
  6. mystreamagain=getIntent().getExtra("memap").get("mystream");
Parsed in 0.031 seconds, using GeSHi 1.0.8.4


If you need to pass just one object you would not need to wrap it in the hashmap.

Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Postby Ishtar » Fri Jan 25, 2008 4:54 pm

the name is ISHTAR. Just kidding :wink:

I did not test it, so Im not sure it works.. It was a suggestion. And you would need to wrap it, even if it's just one object, because you can only send Int's, Strings and HashMaps.. Second option: you can also make a static class, with a static member: your vector. You could then access it from anywhere in your program. Both are dirty tricks. Easiest would be to rethink your design (if possible...)

Ishtar
Ishtar
Experienced Developer
Experienced Developer
 
Posts: 50
Joined: Wed Jan 16, 2008 10:22 pm
Location: Netherlands

Postby plusminus » Fri Jan 25, 2008 5:23 pm

Sorry Ishtar ;),

lol, I trusted in the Object-Parameter. They must be kidding:
Make the parameter-type 'Object' and internally allow only 'Integer, String, or HashMap'...... :roll:
public Intent putExtra(String name, Object value)
....
value The data value. Can only be an Integer, String, or HashMap.


Regards,
plusminus
Image
Image | Android Development Community / Tutorials
User avatar
plusminus
Site Admin
Site Admin
 
Posts: 2688
Joined: Wed Nov 14, 2007 8:37 pm
Location: Schriesheim, Germany

Top

Return to General

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest