Android-Rate
Android-Rate copied to clipboard
onClickButton() callback may not happen always
I found that my callback for onClickButton() did not happen. I just followed what is recommended in README.
AppRate.with(this)
.setDebug(BuildConfig.DEBUG)
.setInstallDays(5)
.setLaunchTimes(4)
.setRemindInterval(3)
.setShowLaterButton(true)
.setOnClickButtonListener(new OnClickButtonListener() {
@Override
public void onClickButton(int which) {
==> Log.d("Rate", "onClickButton: " + which);
}
})
.monitor();
From the code, I see that the listener is weak referenced. Since we set the listener at onCreate() and the dialog only pops up when we close the app, it is likely that OnClickButtonListener object is garbage collected since there is no strong reference to this object. If the object is gone, the callback won't happen.
I think the weak reference is used mainly with the assumption that the activity itself is the listener. So the work around is to make activity implement OnClickButtonListener interface and set listener like this: .setOnClickButtonListener(this)
I confirm if Activity itself implements OnClickButton interface, the callback works correctly. But this shall be fixed if my above understanding is correct. It is very common to create listeners inline in java.
Hi @rpattabi ,
Fixed in https://github.com/Vorlonsoft/AndroidRate since Release 1.2.1