I have some values and want to pass with activity so that I can show in TextViews of Activity, I am unable to understand such a concept, so what should I do? Simply I want to make constructor but unable to understand it that how will it be done, I am new to android programming, so needed help.
Asked
Active
Viewed 4,210 times
0
-
1Searching for "Start activity with parameters" returns http://stackoverflow.com/questions/3913592/start-an-activity-with-a-parameter among others – rds Jul 20 '11 at 08:41
4 Answers
3
Start by reading the documentation at developer.android.com about intents and intent extras.

Manfred Moser
- 29,539
- 13
- 92
- 123
2
In android if you launched an activity there is a method called onCreate execute automatically.You can send values using Intent to the activity and can retrieve them in the Activity

Rasel
- 15,499
- 6
- 40
- 50
1
If you want to pass one value then you can use intent but if you want to pass multiple values then using "Bundle" is best way.
Bundle bundel = new Bundle();
bundel.putStringArray("key1",strings);
bundel.putStringArray("key2",stringsofids);
bundel.putString("key3", str31);
bundel.putStringArray("key4",stringsbakup);
bundel.putString("key5", str1);
bundel.putString("key6", str4);

Andy
- 11
- 1
1
The Activity (sub)class must have a default constructor without any parameters so that the system can instanciate it at run time.
To pass "parameters" to activities, you need to use the extra bundle of the intent.
Intent i = new Intent(this, MyActivity.class);
i.putExtra("com.sample.MyParameter", 666);
startActivity(i);

Vincent Mimoun-Prat
- 28,208
- 16
- 81
- 124