我正在用Android Studio(JAVA)编写程序。它是使用Firebase服务(数据库和身份验证)的纸牌游戏管理器。 当我从实时数据库中检索数据时,应向他们显示的Activity并没有执行该操作,程序返回到Main Activity。
日志中没有错误。
database = FirebaseDatabase.getInstance("https://gestionalebriscola-a8a93.firebaseio.com/");
myRef = database.getReference("Tornei");
myRef.keepSynced(true);
myRef.addValueEventListener(new DataSingleHandler(this));
listv_Tornei.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
showTorneoActivity(i);
}
});
///////这是第二部分
private class DataSingleHandler implements ValueEventListener{
private Context context;
public DataSingleHandler(Context context){
this.context=context;
}
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
torneiSulServer=new ArrayList<>();
for(DataSnapshot snapshot : dataSnapshot.getChildren()){
Log.d("GET",snapshot.toString());
try{
Torneo torneo = snapshot.getValue(Torneo.class);
torneiSulServer.add(torneo);
} catch (Throwable e) {
Log.d("GET", "onCreate eror", e);
}
}
torneiSulServerAdapter = new ArrayAdapter<>(context,android.R.layout.simple_list_item_1,torneiSulServer);
listv_Tornei.setAdapter(torneiSulServerAdapter);
}
@Override
public void onCancelled(@NonNull DatabaseError databaseError) {
}
{private void showTorneoActivity(int i)
{ Intent intent = new Intent(this,ShowActivity.class);
Bundle data = new Bundle();
data.putSerializable("TORNEO",
torneiSulServer.get(i));
intent.putExtra("TORNEO",data);
startActivity(intent); }}