简体   繁体   English

启动时未显示对话框片段

[英]Dialog Fragment Not Displaying on Launch

So I have some application, on startup it launches a splash screen activity and checks to see if a user account has been linked to the app. 因此,我有一些应用程序,在启动时会启动启动屏幕活动,并检查用户帐户是否已链接到该应用程序。 If one has the app launches the main activity and bypasses the splash silently. 如果有人启动了该应用程序,则该应用程序将启动主要活动并以静默方式绕过启动。 If there is no user account it pulls down a database in a AsyncTask and asks the user to Login/Create an Account. 如果没有用户帐户,它将在AsyncTask下拉数据库,并要求用户登录/创建帐户。

On first startup the app syncs with a server and pulls down a database. 首次启动时,该应用与服务器同步并拉出数据库。 I'm trying to get a DialogFragment with an indeterminate progress bar to display as this database is pulled down. 我正在尝试获取一个带有不确定进度条的DialogFragment ,以在该数据库被下拉时显示。 Right now the DialogFragment is created in the onPreExecute() of the AsyncTask , the AsyncTask is executed in the Activity's onStart() method the problem I'm having is that the dialog is not being drawn to the screen. 现在, DialogFragment是在AsyncTaskonPreExecute()中创建的, AsyncTask是在Activity的onStart()方法中执行的,我遇到的问题是未将对话框绘制到屏幕上。

I have debug logging that shows that the dialog's onCreate() is executing and the sync is successful. 我有调试日志记录,它显示对话框的onCreate()正在执行并且同步成功。 The dialog is shown/dismissed in onPreExecute() and onPostExecute() respectively both of which execute on the UI thread. 该对话框分别在onPreExecute()onPostExecute()显示/关闭, onPreExecute()都在UI线程上执行。 I realize that if the database download is fast this won't display very long but I'm not seeing even a brief flash of the dialog in the emulator. 我意识到,如果数据库下载速度很快,它将不会显示很长时间,但是在仿真器中甚至看不到对话框的简短闪烁。

Could this be a 'problem' with the emulator where all the dialog's frames are being skipped or am I not creating the dialog at a point where it would actually be drawn to the screen. 这可能是模拟器的“问题”,其中所有对话框的框架都被跳过了,还是我没有在实际绘制到屏幕上的位置创建对话框。

From your description I see 2 possible reasons: 从您的描述中,我看到两个可能的原因:
1. Maybe you doesn't show right the DialogFragment, see example . 1.也许您没有正确显示DialogFragment,请参见example
2. The AsyncTask is launched in a different thread (Not on UIThread), so if you need to access the UIThread (from the AsuncTask), try to override onProgressUpdate see tutorial . 2. AsyncTask在另一个线程中启动(不在UIThread上),因此,如果需要访问UIThread(从AsuncTask中访问),请尝试覆盖onProgressUpdate请参见教程
Hope it was helpfull. 希望对您有所帮助。

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

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