检查活动是否是活动的 [英] Check whether activity is active

查看:98
本文介绍了检查活动是否是活动的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用中有一定的活动侦听器的问题。

I'm having a problem with a listener in a certain activity.

的问题是,此侦听包含alert.show();可以称之为后,我们试图推动一项新的活动(然后给出了一个例外)。

The problem is that this listener contains an alert.show(); which can be called after we try to push a new activity (which then gives an exception).

例如:我在听的活性一种从其他手机的信号。我preSS回,并尝试运行新的b活动,但该程序崩溃,因为alert.show的()A的监听器。

e.g.: I'm listening in activity A for a signal from an other phone. I press back and try to run a new activity B but the program crashes because of the alert.show() A's listener.

ERROR/AndroidRuntime(3573): android.view.WindowManager$BadTokenException: Unable to add window -- token android.os.BinderProxy@476c21c0 is not valid; is your activity running?

我可以签入的听众这个活动是否活跃,然后显示警告或不依赖于该值?

Can I check in A's listener whether this activity is active and then show the alert or not depending on this value?

推荐答案

有可能是一个更简单的方法可以让我没有想到的,但一种方法是实现它自己。在 onResume()您有一个成员变量 mIsRunning 设置为true和的onPause()返回假。使用此布尔你应该知道不要叫 alert.show()的回调。

There might be an easier way I can't think of but one way is to implement it yourself. On onResume() you set a member variable mIsRunning to true and on onPause() back to false. Using this boolean you should know not to call alert.show() on your callback.

这篇关于检查活动是否是活动的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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