Get the value of my id generated with the push in firebase

0

How do I go through these ids that I generated through the push and I can get the value of this id pq in the future I will need to use for the time that the user clicks on a list I move from parameter that id to another screen so that I can load this piece of information there

finalFirebaseDatabasedatabase=FirebaseDatabase.getInstance();finalDatabaseReferenceref=database.getReferenceFromUrl("https://appassistencia-8e7b9.firebaseio.com/empresa");

ref.addChildEventListener (new ChildEventListener () {

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {


                final String areaAtuacao = (String) dataSnapshot.child("areaAtuacao").getValue();
                final String empresaCidade = (String) dataSnapshot.child("empresaCidade").getValue();
                final String empresaEstado = (String) dataSnapshot.child("empresaEstado").getValue();
                final String empresaImagem = (String) dataSnapshot.child("empresaImagem").getValue();
                final String empresaNome = (String) dataSnapshot.child("empresaNome").getValue();

I am getting the id aq with the String s, but the first time it comes null and with an id less at the end.

           System.out.println(s);
                FirebaseStorage storage = FirebaseStorage.getInstance();
                StorageReference storageRef = storage.getReferenceFromUrl("gs://appassistencia-8e7b9.appspot.com/imagens").child(empresaImagem);

                try {
                    final File localFile = File.createTempFile("images", "png");

                    storageRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
                        @Override
                        public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
                            Log.e("Test", "success!");
                            bitmap = BitmapFactory.decodeFile(localFile.getAbsolutePath());
                            items.add(new Empresa(empresaNome, areaAtuacao, empresaCidade, empresaEstado, bitmap));

                        }
                    });
                } catch (IOException e) {
                    e.printStackTrace();
                }
            System.out.println(s);
            }

        @Override
        public void onChildChanged(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onChildRemoved(DataSnapshot dataSnapshot) {

        }

        @Override
        public void onChildMoved(DataSnapshot dataSnapshot, String s) {

        }

        @Override
        public void onCancelled(DatabaseError databaseError) {


        }});




recycler.setAdapter(new EmpresaAdapter(items, new EmpresaAdapter.OnItemClickListener() {

    public void onItemClick(Empresa item) {


        startActivity(new Intent(EmpresaActivity.this, Activity_Tab_Empresa.class));


    }
}));

}}

    
asked by anonymous 04.05.2017 / 20:48

1 answer

1

String s indicates the key of the previous element. The first s is NULL because it has no key before the first key in the database. And following this logic, the last s will always be the penultimate key.

The key of the current element can be obtained through DataSnapshot:

        @Override
        public void onChildAdded(DataSnapshot dataSnapshot, String s) {
            String key = dataSnapshot.getKey(); 
        }
    
24.02.2018 / 12:12