Reputation: 105
I have around 12k monthly active users, the app is an exchange rate app for only 2 currencies, so naturally, there isn't much to store, just 2 numbers, the buy rate and the sell rate.
However, my download usage per month is reaching 4.7GB, why?
This is the code that queries the database in my native android app (Java):
private void getRefValue(DatabaseReference ref, TextView view) {
ref.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NotNull DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
String textData;
if (view.getTag().toString().equals("sellText")) {
textData = "Sell: " + value;
editor.putString("sell", value);
} else {
textData = "Buy: " + value;
editor.putString("buy", value);
}
editor.apply();
view.setText(textData);
}
@Override
public void onCancelled(@NotNull DatabaseError error) {
// Failed to read value
Log.d("Failed to read", error.getMessage() + " " + error.getDetails());
}
});
}
Instead of making a separate function for each textView to be updated, I check the tag of the view to see if it's the sell view or the buy view, and I update its text accordingly, the editor
variable is a sharedPreferences editor, I use shared preferences to show offline users the last available rate.
The database reference is passed as an argument when calling the function, it gets called twice, once for each entry in the DB.
Is my code doing anything wrong? I'm not very experienced with Java or native android.
Upvotes: 0
Views: 262
Reputation: 29
I had faced the same issue and faced huge billing from Firebase. Problem is that every time when a user comes into the application. It hits to the Firebase which uses data. Like you have used Shared Preferences for offline users but you just need to hit the event listener only when there is any change the database. For that you can make the versions if there is any change in the version it will check for the data otherwise it will show the data from shared preference only even if there is internet connection in the device.
I reduce the billing amount from 2Lacs to 2.5K only
Upvotes: 1