Java – using Otto, if I call it directly elsewhere, the method will only subscribe

I have a problem that one of my subscription methods will not be called for posts of the correct event type unless the subscription method is used (called) elsewhere

Here is some information about the code:

>The method of one of my classes is annotated with @ subscribe. > By using the debugger to execute the code step by step, I found that in my specific case, this class does not use the @ subscribe annotation method. > Unless I call this method directly at some point in time (whenever, or even actually call it at runtime), my post will not work. > The IDE (Android studio) tells me that "methods will never be used"

Of course, I can call this method in a piece of code. I believe it will never be dismissed, but this is obviously a terrible practice and it violates the purpose of this post / subscription paradigm.

Or I can make the method static, but I'd rather not, because I use member variables in it

Although Otto's example uses a similar pattern, why does this happen to any solution

Solution

It turns out that this is a Proguard problem Fix it by adding the following line:

-keepclassmembers class ** {
    @com.squareup.otto.Subscribe public *;
    @com.squareup.otto.Produce public *;
}
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>