0

I am creating an app in which coins/points increases on watching reward video ads and those coins/points should be saved to firebase.

For example: every time on button click the coins value increases to 10 points. Now when I completely destroy the app and open it again, the points value should show the same, not zero

Here is my code till now without database implementation

private TextView mText;
private int coinCount;
mText = (TextView) findViewById(R.id.money);
coinCount = 0;
mText.setText(" " + coinCount);


Button button = (Button) findViewById(R.id.buynow);
button.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        if (coinCount <= 29) {
            //if(coinCount <30) {
            new MaterialStyledDialog.Builder(MainActivity.this)
                    .setTitle("Not Enough Coins")
                    .setDescription("Watch the Ad To Get 10 coins")
                    .setIcon(R.drawable.ic_money)
                    .withIconAnimation(true)
                    .withDialogAnimation(true)
                    .withDarkerOverlay(true)
                    .setHeaderColor(R.color.color)
                    .setPositiveText("Get some coins")
                    .onPositive(new MaterialDialog.SingleButtonCallback() {
                        @Override
                        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                            mRewardedVideoAd.show();
                        }
                    })

                    .show();

        } else {
                coinCount = coinCount - 30;
                mText.setText(String.valueOf(coinCount));

            }

    }
});

My queston is how to Save The Coin value to DATABASE and retrieve it ?

Zombie
  • 404
  • 10
  • 18
Joy Dey
  • 563
  • 1
  • 5
  • 17
  • maybe this can help: https://stackoverflow.com/questions/48307610/how-to-save-users-score-in-firebase-and-retrieve-it-in-real-time-in-android-stud – Zombie Jun 09 '18 at 18:03
  • I saw it. I am a bit confused about how to implement it – Joy Dey Jun 09 '18 at 18:04

0 Answers0