简体   繁体   中英

Layout duplicated with fragment and activity

I made a Quiz game with 50 questions, and when finishes the question 50 fragment, I call the Score activity, that shows the score of its user. And I created on this activity (score activity) a Button "Play Again", and I called the Main Activity( the code inside the Button "Play Again" is:

Intent intent1 = new Intent ("com.example.moresche.englishqigame.MainActivity");
startActivity(intent1);

and when I click on this Button the app crashes and initializes with duplicated layout between question 50 fragment and the main activity. How can I solve this problem? Why the question 50 fragment still up?

Switch to

Intent intent1 = new Intent (this, MainActivity.class);
startActivity(intent1);

If that doesn't solve your crash, then you'll need to post the actual crash from logcat.

call finish() method before calling score activity This will kiss your questions activity

Then call finish() while navigating to the MainActivity

This way, user cannot come back to score screen again

Finally, as @craya said, call the activity like below

finish()
Intent intent1 = new Intent (this, MainActivity.class);
startActivity(intent1)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM