[android-developers] When switching content views sending over a variable?

2010-09-14 Thread arberb
Im trying to switch content views on my application and I wanna send
over a variable along with it.
So my main class has a button and when you click it, it brings you to
a different content view (I have an intent setup) so yeah in the main
class it has a variable and I wanna bring it to the new content view.
how can I do this?

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] When switching content views sending over a variable?

2010-09-14 Thread Kostya Vasilyev
 I assume you mean that one activity starts another using startActivity 
or startActivityForResult.


- Define a String constant that will serve as the key to access data:

public static final String EXTRA_KEY = some string value;

- In the first activity, add data to the intent:

Intent intent = new Intent(this, NewActivity.class);
intent.putExtra(EXTRA_KEY, value here);

- In the second activity, get the intent used to start the activity, and 
then the value from the intent:


protected void onCreate(Bundle savedInstanceState) {
..
Intent intent = getIntent();
String value = intent.getStringExtra(EXTRA_KEY);

}

-- Kostya

14.09.2010 15:37, arberb пишет:

Im trying to switch content views on my application and I wanna send
over a variable along with it.
So my main class has a button and when you click it, it brings you to
a different content view (I have an intent setup) so yeah in the main
class it has a variable and I wanna bring it to the new content view.
how can I do this?




--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en