如果方向转变Android应用程序崩溃应用程序、方向、Android

2023-09-04 06:19:19 作者:你不找我不扰i

我创建了一个游戏程序,我通过一个叫分享按钮分享一些细节到Facebook。当我完成它要求在对话框中的名称的游戏,它表明没有问题,在同一方向(横向/纵向)工作时。如果我打的景观,完成比赛,翻转手机转为纵向来输入我的名字,然后点击共享,它会崩溃。如何克服这个问题?

I have created a game app where I share some details to Facebook through a button called Share. When I finish the game it asks for the name in a dialog box, it shows no problem when working on the same orientation (landscape/portrait). If I'm playing in landscape, finish the game, flip the phone to portrait to type my name in, then click "Share" it will crash. How to overcome this problem?

推荐答案

这是活动重新启动的方向改变时。我猜这重新出现在你的code为不保存所需的信息。您可以通过处理具体配置不停地翻动自己这个默认行为(即:方向变化)。在做这方面的一个很好的教程就设在这里:处理运行时更改

An activity is restarted when the orientation changes. I'm guessing your code isn't saving needed information before this restart occurs. You can stop this default behavior by handling specific configuration changes yourself (ie: orientation change). A good tutorial on doing this is located here: Handling Runtime Changes