java - How to stop the timer after certain time? -


i have android application has timer run task:

time2.scheduleatfixedrate(new timertask() {         @override         public void run() {             sendsamples();         }     }, sampling_interval, sending_interval); 

lets sampling_interval 2000 , sending_interval 4000.

so in application send reading values sensor server. want stop sending after 10000 (10 seconds).

what should do?

try

        time2.scheduleatfixedrate(new timertask() {             long t0 = system.currenttimemillis();             @override             public void run() {               if (system.currenttimemillis() - t0 > 10 * 1000) {                   cancel();               } else {                   sendsamples();               }             } ... 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -