我的service有个内部类Servicehandler继承自Handler,new 这个ServiceHandler的那行提示“This handler class should be static or leaks might occur”。
我这个ServiceHandler不能为static,里面有非静态的成员变量,应该怎么办?
...全文
31857打赏收藏
This handler class should be static or leaks might occur
我的service有个内部类Servicehandler继承自Handler,new 这个ServiceHandler的那行提示“This handler class should be static or leaks might occur”。 我这个ServiceHandler不能为static,里面有非静态的成员变量,应该怎么办?
你的内部类中没有访问service中的成员没有?如果没有就没关系,内部类声明为static,可以和普通类一样使用,而不需要绑定到外部类的对象上
[/Quote]
没有访问外部类的成员,但是有传进来参数啊,这就是那个类
final class ServiceHandler extends Handler{
public ServiceHandler(Looper looper) {
super(looper);
// TODO Auto-generated constructor stub
}
@Override
public void handleMessage(Message msg) {
// TODO Auto-generated method stub
//super.handleMessage(msg);
if(msg.what==1)
{
Context context=(Context) msg.obj;
int hour=msg.arg1;
int minute=msg.arg2;
boolean start=true;
}
if(msg.what==2)
{
}
}
}