开发者

android: pros/cons of manually handling config changes

I don't want my Activity to be re-created every time the device is rotated, so I've put the android:configChanges="keyboardHidden|orientation" tags in my manifest file.

Is there any disadvantage to this approach? The screen seems to re-layout automatically 开发者_开发问答upon rotation, and everything works well, with the advantage that i don't need to re-initialize all the objects in my activity every time the screen rotates.

Thanks!


Not sure if you still want an answer, but I'm guessing the disadvantage is that it doesn't really let you know your applications works correctly if, say, the user answers the phone and puts your app in the background. In other words, if your app can survive orientation change with minimum difference in state, then it should be able to handle a dialer taking focus away.

Additionally, if you have any changes in resources depending on orientation or keyword (for example, if you have a dashboard screen and you want to change the position of your home buttons), Android won't automatically load those for you.

Looking at Google's design patterns, it seems Google uses both approaches. In the new Google+ app, for instance, they are not relying on the configChanges option because LogCat shows the unexpected resume of activity message, which for me shows only when an activity is destroyed and re-created. Google does use the option in other places, such as the Calendar application to edit appointments, and the Browser I think.

So it'd be a good idea to design your application without configChanges and add it later once everything works if there are some things that are inviable to restore (like whether the context menu is showing).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜