Activity类以外的Android环境 [英] Android context outside of Activity class
本文介绍了Activity类以外的Android环境的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图来处理我的应用程序异常。我想记录异常,然后用面包来提醒,有一个问题的用户。我有我的所有类的扩展活动这一工作的发现。
I am trying to handle exceptions in my application. I am trying to log the exception, then use Toast to alert the user that there was a problem. I have this working find in all my class's that extend Activity.
然而,在不延长活动我不能使用敬酒方法,我不能让当前的上下文中的任何类。有一个简单的方法来解决这个问题还是应该我所有的类的扩展活动?
However, in any class that does not extended activity I can not use the toast method as I can't get the current context. Is there a simple way to get around this or should all my class's extend Activity?
推荐答案
您只需通过上下文
当你调用自Activity类调用非活动
类像
You just pass Context
When You call Non-Activity
class from Activity class call Like
YourNonActivtyClass obj = new YourNonActivtyClass(Activity.this);
这篇关于Activity类以外的Android环境的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文