Android 服务的内部活页夹类:静态还是非静态?
我有一个内部活页夹类服务:Android 服务的内部活页夹类:静态还是非静态?,android,android-service,Android,Android Service,我有一个内部活页夹类服务: public class MyService extends Service{ private final ServiceB binder = new ServiceB(); @Override public IBinder onBind(Intent intent) { return binder; } //inner binder class class NewsServiceB extends Binder{ ...
public class MyService extends Service{
private final ServiceB binder = new ServiceB();
@Override
public IBinder onBind(Intent intent) {
return binder;
}
//inner binder class
class NewsServiceB extends Binder{
....
}
我的问题是:这个模式可以吗?或者我应该使binder类是静态的,可能是对服务的弱引用?请记住,每个binder方法都使用服务的方法,因此使其非静态非常有用,因为代码更干净、更直接
我担心内存泄漏,甚至没有警告显示…我觉得这种模式很好。你为什么担心内存泄漏?嗯…我的服务占用了9MB内存,对我来说太多了。。。