Using Otto, method only subscribes if I call it directly elsewhere
Question
I have an issue where one of my subscribed methods does not get called upon a post of the correct event type unless that subscribed method is used (called) elsewhere.
Here is some relevant information about the code:
- A method of one of my classes is annotated with @Subscribe.
- By stepping through the code with the debugger, I find that under my specific circumstance, the class has no methods annotated with @Subscribe.
- Unless I call the method directly at some point in time (doesn't matter when, or even if it actually gets called at runtime) elsewhere, my post does not work.
- The IDE (Android Studio) notifies me that the "method is never used"
I can certainly call the method in a block of code that I am confident will never fire, but this is obviously terrible practice, and defeats the purpose of this post/subscribe paradigm.
Or I can make the method static, but I'd rather not because I use member variables inside of it.
Any solutions to why this is occuring even though Otto's example uses a similar pattern
Solution
Turns out it was a ProGuard issue. Fixed it by adding the following lines:
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow