我试图来处理我的应用程序异常。我想记录异常,然后用面包来提醒,有一个问题的用户。我有我的所有类的扩展活动这一工作的发现。
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);