机器人从处理程序得到活动实例中的应用 [英] Android getting Activity instance in Application from Handler

查看:73
本文介绍了机器人从处理程序得到活动实例中的应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的处理器为当前活动和应用的一个子类之间进行通信。 子类是有一个线程,处理Web服务调用。 子类还可以具有ProgressDialog实例

I am using Handler for communicating between Current Activity and a subclass of Application. Subclass is having a thread which processes web service calls. Subclass may also have a ProgressDialog instance.

我想告诉ProgressDialog当HTTP调用开始,当通话结束后解雇对话框。

I want to show ProgressDialog when http call is starting and dismiss dialog when call is finished.

有关这种情况发生,我需要从处理程序访问活动。然后使用setOwnerActivity分配活动对话框。

For this to happen, I need to access Activity from Handler. And then assign activity to Dialog using setOwnerActivity.

这可能吗?我尝试和不能没有得到活动的处理程序。最大处理器可以给的是线程,发送消息。

Is this possible? I tried and cant not get activity from Handler. The max Handler can give is Thread which sent message.

推荐答案

应用程序类是不知道哪些活动正在运行的。

The application class is unaware of what activity is running.

这是可以做的唯一的事情就是让应用程序类,了解活动是由不推荐,因为它可能会导致内存问题setter方法​​。

The only thing that can be done is to let application class know about activity is by a setter method which is not recommended as it may lead to memory problems.

这篇关于机器人从处理程序得到活动实例中的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆