Confirmed users
586
edits
(→Java) |
|||
| Line 81: | Line 81: | ||
This is so that in case of ClassCastExceptions you don't get a dangling open resource left behind. | This is so that in case of ClassCastExceptions you don't get a dangling open resource left behind. | ||
=== Timing things === | |||
TLDR: If you're adding stuff for timing, use android.os.SystemClock, rather than something like new Date().getTime(). | |||
Normally in Java the default time-getter is System.currentTimeMillis() since it avoids the overhead of creating a new Date object. However, currentTimeMillis() is subject to change in unexpected ways if the user changes the time on their device, or if daylight savings comes into effect, or whatever. So Android has generously provided android.os.SystemClock which has various functions that you can use to get a better timestamp. Refer to the class javadoc and pick whichever is most suitable. | |||