Pass messsage to child activity

Put your problem here if it does not fit any of the other categories.

Pass messsage to child activity

Postby rockerboy » Sat Nov 14, 2009 3:30 am

Hi,

Currently, I am starting a Child activity from a Parent activity in
the following manner:

public class Parent extends Activity {

private int message;
public Parent()
{
message = 0;
}

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Start child activity
Intent child = new Intent(Parent.this,Child.class);
startActivityForResult(child, 1);
}

}

Is there a way to communicate the message member variable from the
Parent activity to the Child activity? I'm not creating any Child
objects above, so I'm confused as to how one is supposed to send
messages from the Parent to the Child activities. Any suggestions please?

Thanks,
rockerboy
Freshman
Freshman
 
Posts: 8
Joined: Sat Nov 14, 2009 3:27 am

Top

Postby Oleg » Sat Nov 14, 2009 1:58 pm

Hi.
It is very easy use Intent and Bundle objects.

Simple implementation you can find here
http://thedevelopersinfo.com/?p=96
Oleg
Experienced Developer
Experienced Developer
 
Posts: 57
Joined: Wed Nov 28, 2007 1:49 pm
Location: Ukraine

Postby qlimax » Sat Nov 14, 2009 6:52 pm

:idea: isn't google your friend

you can use bundles as oleg said, but also:

btw intent.putExtra("paramname",XXXtype param);
...
-...
start the intent



then

in the child Activity

getIntent().getXXXXXtypeExtra("paramname")


it's a kind of a hashmap into the intent.


bye
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby rockerboy » Sat Nov 14, 2009 11:10 pm

Thanks for that. Very helpful.
rockerboy
Freshman
Freshman
 
Posts: 8
Joined: Sat Nov 14, 2009 3:27 am

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: Exabot [Bot] and 19 guests