I have stored some data in realtime database under autenticated key using shared preferences. I used SharedPreferences
because I used multiple pages for getting
You are getting that unwanted extra level (all
) in the database because when you are write the data using:
reference.child("User").child(Objects.requireNonNull(mAuth.getUid())).setValue(sp);
You are passing to the setValue()
method a SharedPreferences
object:
SharedPreferences sp = getSharedPreferences("Mypref", Context.MODE_PRIVATE);
And not the data that is stored in that object. Inside your sp
object, the data is stored as a Map
containing key and value pairs. The first key in that object is all and the value is your actual data. That's the reason you have that structure. To solve this, simply get the data out from your sp
object, save it into a Users
object and write it to the database. In this way you'll have a database tree without that extra node.