【问题标题】:Service not being Started, Object not being notified未启动服务,未通知对象
【发布时间】:2014-06-20 19:33:28
【问题描述】:

我正在使用代码

Someactivity

Intent Service = new Intent(getBaseContext(), Service.class);
startService(Service);
try{
    synchronized (populateAlbumList_Running) {
        populateAlbumList_Running.wait();
    }catch(InterruptedException e){
        e.printStackTrace();
    }
}

我正在从服务调用 Someactivity.populateAlbumList_Running.Notify()

但问题是服务甚至没有启动 我得到的应用程序永远没有响应 但如果我删除 wait() 并启动服务,它的工作正常,请帮助

【问题讨论】:

    标签: android object service concurrency


    【解决方案1】:

    服务在主线程中启动。来自documentation

    请注意,服务与其他应用程序对象一样,在主程序中运行 他们托管进程的线程。

    因此,如果您在主线程上wait(),他们将没有机会启动。您应该改为从后台线程运行此代码。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-11
    相关资源
    最近更新 更多