Search code examples
androidfirebase-realtime-databasetreemaphuawei-mobile-services

TreeMap not sorting elements on some devices


My Object:

public class School{
TreeMap<String, int> classes = new TreeMap<>();
}

This is how I save the objects to Firebase Realtime DB:

 mDatabase.child("School").setValue(school);

This is how I retrieve the objects fromFirebase Realtime DB:

ValueEventListener listener = new ValueEventListener() {
    @Override
    public void onDataChange(DataSnapshot dataSnapshot) {
        SChool s = dataSnapshot.getValue(School.class);
    }

    @Override
    public void onCancelled(DatabaseError databaseError) {
    }
};

The problem: Using TreeMap should ensure the ordering of keys, which are always written correctly on the DB as shown below:

enter image description here

Testing the app on various emulators and physical devices shows expected normal behavior, which is the viewing of Classes in an ascending sorting manner same as what is visible on the DB above.

However, I get complains from app users that the list has no sorting order at all on their devices. These devices include: Huawei Mate 8, Oppo F9.

I am losing my mind, Am I missing something here?


Solution

  • I tried uploading the app again but this time using the "generate signed APK", and it works fine on all devices right now. Even the devices that the users had issues with my app with.

    It seems that when publishing the app on google play using "generate signed bundle" causes various issues including the above one. It causes confusion as a lot of devices have no problem in making the app work correctly with the normal expected behavior of TreeMap. However, on other devices the TreeMap doesn't sort keys at all.

    Also check this, it is also because of uploading to google play using "generate signed bundle".