android - start an activity after button click -
i want start activity once after application starts. did code:
boolean isfirstrun = getsharedpreferences("preference", mode_private) .getboolean("isfirstrun", true); if (isfirstrun) { //show start activity startactivity(new intent(mainactivity.this, firstlaunch.class)); toast.maketext(mainactivity.this, "first run", toast.length_long) .show(); } getsharedpreferences("preference", mode_private).edit() .putboolean("isfirstrun", false).commit();
but didn't work thing want. want when click on button , launch activity. main activity launches
to start activity, need use intents. , can call when button clicked so:
button mybutton = (button) findviewbyid(r.id.my_button); mybutton.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { intent intent = new intent(currentactivity.class, nextactivity.class); startactivity(intent); }
you can read more starting activities here.