【问题标题】:Calling a Async task from a service in android从android中的服务调用异步任务
【发布时间】:2015-03-27 11:39:29
【问题描述】:

大家好,我在从服务调用 Asynctask 时需要帮助

我的 Main 类中有一个 Asynctask 扩展了 Fragment 我想在每个定期间隔时间或在这种情况下需要下一次更新时调用这个 Asynctask 我正在考虑在我的应用程序中实现服务类,任何人都可以指导我如何我能做到吗

提前致谢

【问题讨论】:

  • 你可以使用处理程序。
  • 嗨,Anshul,你能举出任何实现按钮点击处理程序的例子
  • 来自文档:A Service is an application component that can perform long-running operations in the background and does not provide a user interface. Another application component can start a service and it will continue to run in the background even if the user switches to another application. 为什么要重新发明轮子?

标签: java android android-asynctask android-service


【解决方案1】:

onCreate 中创建一个处理程序,如下所示:

new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
        }
    }, SPLASH_TIME_OUT);

这里的 SPLASH_TIME_OUT 是一个整数,它告诉时间一次又一次地调用这个方法。

private static int SPLASH_TIME_OUT = 1500;

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    • 2016-11-23
    • 2013-11-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多