-4

first of all, i'm a noob at java programing for android. Now, I have a button in the main layout that suppose to call an activity, now what do I write in the onClick method of the button? and I can't use onCreate in the activity that is being called, so what do I use in there? thanks

Someonation
  • 175
  • 10
  • 3
    This is a very trivial task, it takes less effort to google this, than to ask a question here, for which you have already gotten suggestions that it may have already been asked. – Tomislav Markovski Dec 25 '11 at 20:04

4 Answers4

1

Put this code in the onClick method:

Intent intent = new Intent(getApplicationContext(), Activity.class);
startActivity(intent);

The system will start the activity Activity as soon as possible, which will lead to it's onCreate method being called.

Jong
  • 9,045
  • 3
  • 34
  • 66
1

This will start new activity.

Intent i = new Intent(getApplicationContext(), MyNewActivity.class);
startActivity(i);
Tomislav Markovski
  • 12,331
  • 7
  • 50
  • 72
0

You basically follow this pattern:

onClick() {
    Intent i = new Intent(this, <TargetIntent>.class);
    startActivity(i);
}
Heiko Rupp
  • 30,426
  • 13
  • 82
  • 119
0

You need to create Intent first and pass your current activity instance and nect activity to it. Then call that activity through startActivity().

Intent i = new Intent(getApplicationContext(), MyNewActivity.class);

startActivity(i);
MattAllegro
  • 6,455
  • 5
  • 45
  • 52
Ranjit Mishra
  • 440
  • 4
  • 8