A
A
Alexander Popov2016-08-24 14:52:00
Android
Alexander Popov, 2016-08-24 14:52:00

RxJava + Android how to set the minimum function execution time?

Essence of the question:
- when downloading data from the network, we show the progress bar, it is necessary that there be a minimum function execution time of 1 sec, so that there would be no blinking (if the Internet is fast and the data is loaded in 0.0001 sec), i.e. if the data loaded, for example, in less than 1 second, then we still wait for this 1 second to pass.
The options when we wait 1 second for nothing are very bad, it is necessary that at this time we have already loaded the data.
well, respectively, we are talking about RX, how to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
MikkiMouse, 2016-08-24
@MikkiMouse

A snippet of measuring the execution time of a method from SO:

long startTime = System.nanoTime();
methodToTime();
long endTime = System.nanoTime();

long duration = (endTime - startTime);  //divide by 1000000 to get milliseconds.

In principle, you can compare duration with a second and, if necessary, stick the method for the desired number of milliseconds.

D
Denis Zagaevsky, 2016-08-24
@zagayevskiy

I think you need throttleWithTImeout().

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question