I am working on an android app and when I run the main activity the app runs as I want it to but stops after you die in the game. I want to make a restart button appear after you die in the game. So far I've made a new layout with a button and the background of the main activity. I made a new class in my source folder and have set up an onclicklistener but I'm not sure what code will make the the button start the main activity start again.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
You could just call
Activity.recreate();
if you're api level is 11 or above.you can add the following code to your onclick method:
by adding the following code, you are restarting the same activity... without going back to the previous one.
UPDATE
here how you can change and restart the game, you need to add flags to start the activity over.
try it out, hope it works for you