I agree with R. Zagorsky, but I have a different approach.
Use TrafficStats to get the number of packets received / sent, subtract the last amount from it and then save it using SharedPreferences along with the last amount. Now, to handle a device restart, always check if the last counter is greater than the current amount. If so, reset the last amount is 0. Also track when the month began. Once the month is over, remember to reset the count to 0!
If you want to track the invoice for the previous month, use the list. At the end of the month, add the total amount to the array at the index of the month number. Also, keep in mind that the first index is 0, not 1. Thus, you will need to shift the array by 1 value in order to be able to directly use the month number to query your list.
This has an advantage over the idea of โโR. Zagorsky (which is also not bad) that it can be used from level 8 api at least for TrafficStats.
I hope I helped: D
Rippr source share