Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我需要在 android 部分为 Timer 找到一个替代方案。我需要检查并找出是否有任何消息来自服务器端而不单击任何事件。期待您的宝贵建议
试试这个代码,
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor(); scheduler.scheduleAtFixedRate(new Runnable() { public void run() { // call service Log.v("Scheduler--", "1"); } }, 0, 10, TimeUnit.SECONDS);