android - How to retrieve and update specific values in firebase -


i have been working on application user getting awarded point completing challenge. user getting awarded 10 points each completed challenge. need make user score updating each time user completes challenge, in other words points pulled database , added points. (points needs update userid match userid)

how approach problem, suggestions.

public void stopactivity(){     alertdialog.builder builder = new alertdialog.builder(this);      builder.settitle("confirm");     builder.setmessage("are sure want stop?");      builder.setpositivebutton("yes", new dialoginterface.onclicklistener() {          public void onclick(dialoginterface dialog, int which) {              // activity results             string speedtext = speedtxt.gettext().tostring();             string distancetext = distancetxt.gettext().tostring();             string timetext = timetxt.gettext().tostring();              toast.maketext(getapplicationcontext(),"your result is: " + "\n" + speedtext + "\n" + distancetext + "\n" + timetext, toast.length_long).show();              //if result better             if(double.parsedouble(speed_challege) == double.parsedouble(speedtext) || double.parsedouble(speed_challege) < double.parsedouble(speedtext) ){                 toast.maketext(getapplicationcontext(),"you completed challenge", toast.length_long).show();                  //award points if challenge completed                 final databasereference newresult = leaderboard.push();                 string username = mcurrentuser.getemail();                  //trim email leaving username                 int index = username.indexof('@');                 username = username.substring(0,index);                  newresult.child("username").setvalue(username);                 newresult.child("uid").setvalue(mauth.getcurrentuser().getuid());                 newresult.child("score").setvalue(score);             }              //if result worse             else{                 toast.maketext(getapplicationcontext(),"hard luck try again", toast.length_long).show();             }              dialog.dismiss();         }     }); 

enter image description here

have added java class have **firebase context ** ?

 com.firebase.client.firebase;  import com.google.firebase.firebaseapp;  import com.google.firebase.database.firebasedatabase;   public class `firebasecontext` extends android.app.application { @override public void oncreate() {     super.oncreate();     enter code herefirebase.setandroidcontext(this);     if(!firebaseapp.getapps(this).isempty()){         firebasedatabase.getinstance().setpersistenceenabled(true);     }   } } 

Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -