zoukankan      html  css  js  c++  java
  • android service基础

    service基础知识点总结


    service启动方式分为两种

    • startService(Intent intent) onCreate-->onStartCommand,其中onStartCommand一定会被执行。stopService()关闭service
    • bindService(Intent service,ServiceConnection conn,int flags) onCreate-->onBind,其中onBind方法只被调用一次,通过unBindService()关闭service

    start一个service后,service运行在独立的线程中,不再和原来的组件有任何关联。bind一个service后,service给组件提供了一个接口,可以互相交互。

    在写service的demo时遇到异常:java.lang.IllegalArgumentException: Service Intent must be explicit: Intent。服务意图必须是显示声明的。

    解决方法:

    Intent intent = new Intent();  
    intent.setAction("com.yulore.recognize.android");  
    intent.setPackage(context.getPackageName());    //兼容Android 5.0  
    context.startService(intent);  
    

    or

    Intent intent = new Intent(com.yulore.test.AppService.class);  
    context.startService(intent);  
    
  • 相关阅读:
    hdu2089 不要62
    hdu4734 F(x)
    hdu3555 Bomb
    hdu3652 B-number
    hdu4352 XHXJ's LIS
    CodeForces 55D Beautiful numbers
    数位dp模板
    欧拉函数模板
    UVALive
    常用正则表达 (转)
  • 原文地址:https://www.cnblogs.com/lxstudy/p/14709982.html
Copyright © 2011-2022 走看看