android-service

来源:互联网 发布:java第三方支付 编辑:程序博客网 时间:2024/06/06 15:42

1. 创建一个service:

public class MyService extends Service {}

2.在清单中申明service

<application>

    <service        android:name=".MyService"        android:enabled="true"        android:exported="true">    </service></application>
3.调用service

Intent intent=new Intent(this,MyService.class);
this.startService(intent);

4.停止service

this.stopService(intent);或者 stopSelf

执行流程:

onCreate() //只执行一次
onStartCommand(Intent intent, int flags, int startId) //每次调用startService 执行
onDestroy() //调用stoService 执行






http://blog.csdn.net/javazejian/article/details/52709857


0 0
原创粉丝点击