【发布时间】:2020-09-07 13:40:12
【问题描述】:
我是 firebase 新手,我想存储一个高分并从 Firebase 实时数据库中检索它。存储按预期工作,但我找不到检索存储数据的教程。官方文档对我来说有点混乱。请帮帮我。
public class result extends AppCompatActivity {
TextView fscore,highs; Button pagain; String scor; int hs,scrcheck;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_result);
fscore=(TextView)findViewById(R.id.finalscore);
highs=(TextView)findViewById(R.id.his);
pagain=(Button)findViewById(R.id.pagain);
scor=getIntent().getStringExtra("score");
fscore.setText(scor);
// need code here to retrieve the existing highscore value from firebase and assign it to highs textview.
//code to update highscore
scrcheck=Integer.parseInt(scor);
if(scrcheck>hs)
{
hs=scrcheck;
FirebaseDatabase.getInstance().getReference().child("highscore").setValue(hs);
}
highs.setText(Integer.toString(hs));
}
提前致谢。
【问题讨论】:
标签: java android firebase firebase-realtime-database