简体   繁体   English

布局与片段和活动重复

[英]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. 我制作了一个有50个问题的问答游戏,当完成第50个问题片段时,我称为“得分”活动,该活动显示其用户的得分。 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. 当我单击此按钮时,应用程序崩溃,并使用问题50片段和主要活动之间的重复布局进行初始化。 How can I solve this problem? 我怎么解决这个问题? Why the question 50 fragment still up? 为什么问题50片段仍然最多?

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. 如果那不能解决您的崩溃问题,那么您需要从logcat发布实际的崩溃问题。

call finish() method before calling score activity This will kiss your questions activity 在调用分数活动之前调用finish()方法将亲吻您的问题活动

Then call finish() while navigating to the MainActivity 然后在导航到MainActivity时调用finish()

This way, user cannot come back to score screen again 这样,用户无法再次返回得分屏幕

Finally, as @craya said, call the activity like below 最后,就像@craya所说的那样,调用活动如下

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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