我已在我的应用中成功实施了Firebase消息传递.在后台工作得很好,当应用程序在前台时,会调用onMessageReceived()(yippee!).
我遇到的问题是我需要动态更新UI,而我仍然坚持实现这一目标的最佳方法.我不想向用户发送应用程序内通知(如示例代码所示),我不确定是否要发送广播,我想要做的就是访问MainActivity以调用方法已经存在,但我没有参考服务中的MainActivity.
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getNotification().getBody() != null) {
Log.d(LOG_TAG, "Message received: " + remoteMessage.getNotification().getBody());
} else {
Log.d(LOG_TAG, "Message received: " + remoteMessage.getData().get("message"));
}
// Call method in MainActivity
// <<< What goes Here?>>>>
}
Run Code Online (Sandbox Code Playgroud)
这似乎是一个简单的用例,但我无法在网上找到任何帮助.
提前致谢
{
"DIV_1" : {
"ACTINACT" : 1,
"COORDINATOR" : "10CA056",
"DIV_CODE" : "BSL",
"DIV_ID" : 1,
"DIV_NAME" : "Bhusawal",
"ERP_LOC_CODE" : "CRB",
"MTIME" : "2017-04-08T11:02:59",
"ZONE_ID" : "ZONE_1"
},
"DIV_10" : {
"ACTINACT" : 1,
"COORDINATOR" : "06CS011",
"DIV_CODE" : "UMB",
"DIV_ID" : 10,
"DIV_NAME" : "Ambala",
"ERP_LOC_CODE" : "NRA",
"MTIME" : "2017-04-08T11:02:59",
"ZONE_ID" : "ZONE_3"
}
}
Run Code Online (Sandbox Code Playgroud)
如何获得DIV_ID?最初我需要比较密钥(Ex :: Here DIV_10)然后DIV_NAME需要得到.提前致谢...

编辑器一直处于插入模式,无法切换到“|”模式。已经尝试了网上的两种方法,取消选中“使用块插入符”和 Fn+enter。Fn+i 可以对一个文件更改一次,但是当我打开另一个文件时,它仍然保持插入模式,并带有矩形区域。
我使用计数器值来计算我的ListView物品.但是当我向下滚动并向后滚动时,它仍会计算代码中的值并更改值.
这个值应该是1和2而不是7和8 ......

这是我的代码
DatabaseReference myQuery = databaseReference.child("Tests").child(PIN).child("Questions");
FirebaseListAdapter<QuizStatistic_list> adapter = new FirebaseListAdapter<QuizStatistic_list>(this, QuizStatistic_list.class, R.layout.list_quiz_statistic, myQuery) {
@Override
protected void populateView(View v, QuizStatistic_list model, int position) {
TextView quizQuestion, questionNumber, ansA, ansB, ansC, ansD;
quizQuestion = (TextView) v.findViewById(R.id.textView_quizQuestion);
questionNumber = (TextView) v.findViewById(R.id.textView_questionNumber);
ansA = (TextView) v.findViewById(R.id.textView_ansA);
ansB = (TextView) v.findViewById(R.id.textView_ansB);
ansC = (TextView) v.findViewById(R.id.textView_ansC);
ansD = (TextView) v.findViewById(R.id.textView_ansD);
quizQuestion.setText(model.getQuestion());
questionNumber.setText(counter.toString());
ansA.setText("A: " + model.getAnswerA());
ansB.setText("B: " + model.getAnswerB());
ansC.setText("C: " + model.getAnswerC());
ansD.setText("D: " + model.getAnswerD());
//This value …Run Code Online (Sandbox Code Playgroud) android listview firebase firebase-realtime-database firebaseui
我一直在浏览文档,但我没有看到更新特定键值的方法(同时保留其余键)。实现这一目标的唯一方法是获取现有数据并使用 set() 覆盖它吗?
我有这样的事情:
firebase.database()
.ref(`/users/${currentUser.uid}/products/${productKey}`)
.set({category: name});
Run Code Online (Sandbox Code Playgroud)
其中产品有许多其他键值对,并且使用 set() 覆盖整个对象,在这种情况下这不是我想要的。
我感谢任何帮助!