JavaNullPointer
JavaNullPointer

Reputation: 1211

Android: Activitylist

I have a question:

I have a list (for example with Names from my friends) in activity "a". When i click on one of the names(example: peter) i want to start a new activity "b". At this activity i want to show number, birthday ... from this person (peter).

Intent intent = new Intent(this, activityb.class);
            startActivity(intent);

Can I insert here a parameter?

How knows activity "b" that activity a clicked the name peter.... ? I dont have any idea.... Normally i will save it with a special parameter for my function... But this is activity.....

Upvotes: 1

Views: 80

Answers (2)

ademar111190
ademar111190

Reputation: 14505

try it:

Intent intent = new Intent(this, activityb.class);
intent.putExtra("Tag", YourClassImplementsParcelable);
startActivity(intent);

and in onCreat at activityb:

Intent intent = getIntent();
YourClassImplementsParcelable variable = (YourClassImplementsParcelable) intent.getParcelableExtra("Tag");

Upvotes: 1

Jap Mul
Jap Mul

Reputation: 18759

You can add extra values to the intent in activity A by using putExtra() and use getStringExtra() (or getLongExtra(), getIntExtra(), etc.) to retreive them in activity B

Take a look at this page: http://developer.android.com/reference/android/content/Intent.html

// Activity A
intent.putExtra("SOMENAME", "SomeString"); // Doesn't have to be a String ofcourse

// Activity B
String s = (String) getIntent().getStringExtra("SOMENAME");

Upvotes: 0

Related Questions