java - Android App quits if you push a button to go back to MainActivity -
I have started preparing an Android app with Android Studio. I created a button in MainActivity (and Android: onClick = "page2") which links to the main activity in the main activity with the following code:
Public Zero Page 2 (View View) {SetContentView (R.layout.activity_page2); }
So far it works well and I can change from mainActivity to Page 2 Activity. Now I tried to make a button on page 2 to link back to main activity, but when I start the emulator and click on the app crash button ..
Any suggestions what's the problem?
This is the reason why you are not actually starting a new activity That the app stops when you press back from the main activity, implement the onClick
method to start a new activity on the button. Something like this:
mButton.setOnClickListener (see new OnClickListener () {public void onClick (see v) {intent = new intent (getActivity (), ActivityToStart.class); // intent Depending on your needs based on your needs based on the introduction (intent); // or startActivityForResult (...). Extra (...)
< P>
Comments
Post a Comment