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);  
    
  • 相关阅读:
    接口内容小结
    接口的静态方法与私有方法
    接口的默认方法
    发红包O
    抽象
    《大道至简》读后感
    重写
    继承中的二义性问题
    数学应用
    继承
  • 原文地址:https://www.cnblogs.com/lxstudy/p/14709982.html
Copyright © 2011-2022 走看看