Android-Rate icon indicating copy to clipboard operation
Android-Rate copied to clipboard

onClickButton() callback may not happen always

Open rpattabi opened this issue 9 years ago • 2 comments
trafficstars

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();

rpattabi avatar Oct 10 '16 14:10 rpattabi

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.

rpattabi avatar Oct 10 '16 14:10 rpattabi

Hi @rpattabi ,

Fixed in https://github.com/Vorlonsoft/AndroidRate since Release 1.2.1

AlexanderLS avatar Sep 05 '18 07:09 AlexanderLS