不让屏幕翻转扰乱你的进度对话框
转载Update: After some
exhaustive testing in a wide variety of different scenarios I have come
to realise this approach doesn't work in all situations and I am yet to
find an elegant solution to handle progress dialogs across orientation
change events!
There's a bug with Android managed dialogs (pop-ups) that has been
annoying me for days. Imagine an application where you need to drill
down to some specific content via a list and detail screen. You click
an item on the list screen to start a long running connection to the
server and the ProgressDialog
is initiated, the user then changes the screen orientation between
landscape and portrait (with the task running and the dialog showing),
the connection finally finishes and the new detail screen (Activity) is
started. On the detail screen the user changes orientation again and
clicks back. In every instance using managed dialogs the connection
pop-up is still running on the list screen even if you have tried to
dismiss it before redirecting. I'm a stickler for perfect usability so
this has been driving me mad.
My solution was to stop using managed dialogs altogether. Instead I
created the following 4 methods to replace the default Android way of
doing things. Notice the static boolean called isMyDialogShowing,
this boolean persists across the entire life cycle of your Activity and
is used to determine whether or not to show the dialog.
The second part of the puzzle is how to use these methods and the
boolean in order to have perfect control of your dialogs across both
Activity and orientation changes. In the onCreate() method the first thing I do is call setUpMyDialog(). If the ProgressDialog is null the method instantiates it. The second thing I do is check the static isMyDialogShowing boolean to see if my connection dialog should be showing. If the boolean is false I don't call the showMyDialog() method.
If the page has just been loaded for the first time the dialog
won't be showing so you will need a user initiated event to start the
dialog. In this example I have used a simple button click. When the
button is pressed I call my showMyDialog() method for the first time and this displays the previously instantiated dialog and sets the isMyDialogShowing static boolean to true. Every time the page is changed via orientation change or redirection I dismiss the dialog via the onPause()
method. Basically that means the dialog is being both shown and
dismissed every time the page changes due to an orientation switch.
The final ingredient is to call the killMyDialog() method when your connection has finished and you are about to start a new Activity. This sets the isMyDialogShowing boolean to false and ensures that the dialog is never showing when you return to the Activity at a later date.
原文引至:http://www.paxmodept.com/telesto/blogitem.htm?id=766
上一篇:Java 垃圾回收测试小实验
下一篇:ASCII码对照表[备忘]
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
利用卡片翻转特效实现时钟效果
利用动画事件监听和requestanimationframe实现时钟的翻牌特效
requestanimatioframe 动画事件监听 时钟 翻牌 重绘 -
进度对话框QProgressDialog
继承于 QDialog 天子骄龙
进度条 重置 最小值 -
进度条-对话框
进度条-对话框
进度条-对话框