i have a singleton service class that pulls data from a server on a set schedule. as soon as the client has received the data, i trigger bus.post(new NewServerResponseEvent());
(http://square.github.io/otto/)
then in my fragments i do this:
@Override
public void onResume() {
super.onResume();
eventBus.register(this);
}
@Override
public void onPause() {
super.onPause();
eventBus.unregister(this);
}
@Subscribe
public void handleNewServerData(NewServerResponseEvent e) {
refreshView();
}
everything works very smoothly as long as i just run it while developing on my testing device. as soon as i build a release version and put that into the play store, that handleNewServerData()
function is never called.
i can't make sense out of this. what differnce does it make to run that whole thing as a release build? is there maybe stuff happening in another thread that cant post to my subscriber?
can someone point me into the right direction?
thanks in advance
Chances are that your release build is run through ProGuard and it deduces that since the subscriber methods are not directly called, they can be safely removed as unused code. Otto invokes the methods via reflection and ProGuard cannot see that.
Add the following to your proguard config file to keep methods annotated with @Subscribe
or @Produce
:
-keepattributes *Annotation*
-keepclassmembers class ** {
@com.squareup.otto.Subscribe public *;
@com.squareup.otto.Produce public *;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With