IMG_20210704_110558.jpg
# android
m
IMG_20210704_110558.jpg
a
Is it inside the range of
Long.MAX_VALUE
? if so, try using a Long. However, I would rethink your design. Looks like you are better of working in millions
c
If it isn't in the range of Long, you can use BigDecimal, which doesn't have a max size (and of course uses more memory etc) I do agree with @andylamax though, it's probably not something you need, don't hesitate to explain what you want to do so maybe we can find a simpler way to do it
z
Why do you need such huge number?
g
System.currentTimeMillis() is the standard "wall" clock (time and date) expressing milliseconds since the epoch. The wall clock can be set by the user or the phone network (see setCurrentTimeMillis(long)), so the time may jump backwards or forwards unpredictably. This clock should only be used when correspondence with real-world dates and times is important, such as in a calendar or alarm clock application. Interval or elapsed time measurements should use a different clock. If you are using System.currentTimeMillis(), consider listening to the ACTION_TIME_TICK, ACTION_TIME_CHANGED and ACTION_TIMEZONE_CHANGED Intent broadcasts to find out when the time changes.
l
I see Thread.sleep and e.printStackTrace, and I have questions.
😅 6
g
Direct answer would be to use BigDecimal as CLOVIS suggested, More practical answer would be to just use Long.MAX_VALUE, which is more than big enough for your loop with 500ms until Sun will burn Earth Even more practical would be just drop this while/check and use infinite loop like while(true), it will also solve issue with the fact that Long.MAX_VALUE will stop working in 300 billion years, also no need to do useless check But to be serious, It looks as a code which just update UI with delay, it very non-optimal implementation, it starts a thread and blocks it just to update something with delay. Looks that you just update LiveData value with 500 ms interval, probably you need something like this instead (if you use coroutines and if I got photo of your code correctly):
Copy code
val points = liveData {
   val counter = 0
   while(true) {
      delay(500)
      emit(counter)
      counter++
   }
}
2
k
use BigInteger
l
While BigInteger allows to have bigger integers, I second what @gildor said, it doesn't seem necessary here. Are you reading us, @Maku Mazakpe?
m
Yes, I'm currently optimizing the code. Thank you @louiscad