一台装载机适用于所有活动
我正在构建一个 Android 应用程序。它解析存储在数据库中的提要。应用程序的每个活动都可以从数据库获取这些数据。
每个Activity也可以调用Service,并使其刷新数据。完成后我想显示一个加载程序。下载服务时,用户仍然可以自由地在活动之间导航。我的问题是;如何显示在用户导航到的所有活动中运行的加载程序?
多谢 :)
Im building an Android application. It parses a feed which is stored in a DB. Each activity of the app is able to get this data from the DB.
Every activity can also call the Service, and make it refresh the data. When this is done I would like to display a loader. While the Service is downloading, the user is still free to navigate between activities. My question is; how can I display a loader that runs in all activities the user navigates to?
Thanks a lot :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以尝试以下操作:
onPreExecute()
以准备全局加载器(例如,如果服务已经下载了一段时间)onProgressUpdate()
并使用它通过询问服务当前状态(负载百分比或其他)来更新全局加载器的状态In
doInBackground
你实现:onPostExecute
以将全局加载器的可见性设置为View.GONE。如果用户在加载尚未完成时退出 Activity,您可能需要实现一种终止 AsyncTask 的方法。
You could try something like:
onPreExecute()
to prepare the global loader (e.g. setting its state to the current level if the service has been downloading for a while)onProgressUpdate()
and use it to update the state of the global loader by asking the Service for the current state (load percentage or something)In
doInBackground
you implement:onPostExecute
to set the visibility of the global loader to View.GONE.You might need to implement a way of killing the AsyncTask if the user switches away from the activity when the loading is not finished yet.
这就是我会尝试做的事情,因为这对我来说似乎是一项不常见的任务:
我会尝试设置一个半透明的 PopupWindow 其中包含进度指示器。每当需要指示加载进度时,我都会触发/关闭此弹出窗口以显示/或不显示...
Here's what I would try to do since it seems to be an uncommon task to me:
I would try to setup a translucent PopupWindow which contains a progress indicator. I would trigger / dismiss this popup to be displayed / or not whenever there's a need to indicate the loading progress...