JLChen
2021-03-16 3617e6eecac94965554487afc50d39b0584324fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package android.serialport.api.sample;
 
import java.util.Calendar;
 
import android.os.Handler;
import android.os.Message;
 
public class Inductor {
 
    public Calendar LastTime = null;
 
    public Inductor() {
        new thread().start();
    }
 
    class thread extends Thread {
 
        @Override
        public void run() {
            super.run();
 
            while (true) {
                try {
                    Thread.sleep(50);
 
                    if (LastTime == null)
                        continue;
 
                    if (Calendar.getInstance().getTimeInMillis() - LastTime.getTimeInMillis() > 10 * 1000) {
                        // 发送handler通知
                        Message msg = new Message();
                        msg.what = ConsoleActivity.INDUCTOR_LEAVE;
                        Fragment_BUS.MainHandler.handleMessage(msg);
                        LastTime = null;
                    }
                } catch (Exception e) {
                    //
                }
            }
        }
    }
}