https://kotlinlang.org logo
#android
Title
# android
m

Maku Mazakpe

07/04/2021, 8:06 AM
IMG_20210704_110558.jpg
a

andylamax

07/04/2021, 8:20 AM
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

CLOVIS

07/04/2021, 8:49 AM
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

Zun

07/04/2021, 2:19 PM
Why do you need such huge number?
g

George Pandian

07/04/2021, 5:06 PM
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

louiscad

07/04/2021, 5:48 PM
I see Thread.sleep and e.printStackTrace, and I have questions.
😅 6
g

gildor

07/05/2021, 8:48 AM
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

Kareem Radwan

07/07/2021, 6:16 AM
use BigInteger
l

louiscad

07/07/2021, 6:37 AM
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

Maku Mazakpe

07/08/2021, 4:09 PM
Yes, I'm currently optimizing the code. Thank you @louiscad
2 Views