Android:如何从线程显示自定义对话框
我对此进行了堆栈,我正在尝试使用 TabLayout 创建应用程序。我有 3 个选项卡(3 个不同的活动)。我还获得了读取我的 GPS 位置的服务 - 效果很好。我得到了发布到网络服务器用户位置的线程 - 这有效。
现在我正在尝试创建线程,询问网络服务器是否有任何用户消息。如果有 - 线程尝试显示自定义对话框(2 个文本视图和图库 - 如果我通过单击按钮从活动中启动操作,它会起作用),并且出现问题我知道我无法更新与主线程不同的 UI 表单线程,但我不知道如何解决这个问题。我尝试使用 AsyncTask - 失败 - 我不想将 AsyncTask 作为内部私有类分配给特定 Activity。
我希望无论用户当前使用哪个选项卡,都可以显示我的自定义对话框。
线程工作正常,但如何显示该对话框。
我读过有关 runOnUIThread 但不知道如何使用它。
有什么想法,有类似的例子吗?
I stack with this, I'm trying to create application using TabLayout. I have 3 tabs (3 different activities). I also got service which reads my gps position - that works fine. I got thread which post to the web server user position - that works to.
Now I'm trying to create thread which ask web server if there are any messages for user. If there are - thread try to show custom dialog (2 text views and gallery - it works if i start action from activity by clicking button), and there problem starts I know i can't update UI form threads different from main thread but i don't know how to work around this. I tried to use AsyncTask - failed - i don't want to assign AsyncTask to specific Activity as inner private class.
I wish I could show my custom dialog regardless of the tab on which user is currently using.
Thread works fine, but how to show that dialog.
I read about runOnUIThread but don't know how to use it.
Any ideas, any similar examples ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 runOnUiThread 很简单。
Using
runOnUiThread
is easy.您需要使用处理程序。 http://developer.android.com/reference/android/os/Handler.html
You need to use a Handler. http://developer.android.com/reference/android/os/Handler.html