How to store and use a vector in Firebase on Android?

1

I'm having a development problem with my app that I can not resolve and can not find something to help me. Such an app was running smoothly with data stored in variables, but by including Firebase I had some problems storing an array.

I made an algorithm in a class that receives and processes two vectors that are initially stored in variables:

The idea is to be able to store a vector (array) in the firebase and to be able to use it normally in my app, being that I can use the properties of the same, like obtaining values array(i) , size array.length , etc. .. because I need to feed another class:

public class Busca_Horario {

    public String[] timeSelect(String[] entrada1, String[] entrada2){

}

Several tutorials on the internet use obsolete firebase commands and did not serve me. Please help me!

    
asked by anonymous 07.08.2017 / 18:58

2 answers

1

Based on Matheus's response, my functional result follows:

I added a simple string to a child in Firebase and I used the following command to fetch this string and make it an array of type String[] .

databaseReference.addValueEventListener(new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        String string = dataSnapshot.getValue().toString();
        String[] array = string.split(",");

        for (int i = 0; i < array.length; i++ )
        System.out.println(array[i]); //Para observar o seu resultado
    }

So, the split() method separates the array every time it finds the "," (comma, in this case, or any other term) at a position of the array String[] array .     

21.08.2017 / 20:37
1

Firebase does not have a feature to distinguish between a String and a Array , so you'll have to create your own vectors.

I usually sort values using ; : -07:35;07:14;08:25;09:65;.....n

Then, when you fetch these values, just give split in String received:

 String[] valoresFirebase = getFirebaseValues().split(';');

Making you create your vector.

    
09.08.2017 / 14:27