开发者

Is it possible to register an inner class of a class as Broadcast receiver

In android, is it possible to register an inner cla开发者_运维知识库ss of a class as Broadcast receiver?

public class A extends AnotherClass {
   public class B extends BroadcasetReceiver {
   }
}

how can I register B of A to listen for an intent?


In that case you can consider registering it with the Context.registerReceiver(). If you can make it static try to reference it this way from your AndroidManifest: AnotherClass$BroadcasetReceiver. Well... if it's static, why don't just create a top-level class?


Static inner classes can be registered as broadcast receivers in the manifest.

The receiver is referred to by .path.to.class.MyClass$MyInnerClass

I don't think it is possible to reference a non-static inner class.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜