0

Just as the title says. I implemented the Snackbar feature in my app, the first time the snackbar pops up it doesn't show the action, but on the second time it does. The code is below.

    IabHelper.OnIabPurchaseFinishedListener mPurchaseFinishedListener = new IabHelper.OnIabPurchaseFinishedListener() {
    @Override
    public void onIabPurchaseFinished(IabResult result, Purchase purchase) {
        if (result.isFailure()) {

            if (result.getResponse() == IabHelper.BILLING_RESPONSE_RESULT_ITEM_ALREADY_OWNED) {
                mIsPremium = true;
                mAdView.setVisibility(View.GONE);
                removebutton.setText("PURCHASED");

                Snackbar.make(findViewById(R.id.container2), "Purchased", Snackbar.LENGTH_LONG)
                        .setAction("UNDO", mOnClickListener)
                        .setActionTextColor(Color.parseColor("#FFAB40"))
                        .setDuration(4000).show();
            }



        } else if (purchase.getSku().equals(ITEM_SKU)) {
            mIsPremium = true;
            mAdView.setVisibility(View.GONE);
            removebutton.setText("PURCHASED");
            Snackbar.make(findViewById(R.id.container2), "Ads have been removed", Snackbar.LENGTH_LONG)
                    .setAction("UNDO", mOnClickListener)
                    .setActionTextColor(Color.parseColor("#FFAB40"))
                    .setDuration(4000)
                    .show();
        }

        mOnClickListener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        };

    }

};
overhound
  • 85
  • 1
  • 7

1 Answers1

0

When you first time call your function your onClickListener is null.

Move:

mOnClickListener = new View.OnClickListener() {
        @Override
        public void onClick(View v) {

        }
    };

Before if (result.isFailure()), or even to some kind of onCreate().

Praeterii
  • 340
  • 6
  • 16