您的位置:首页 > 其它

Service服务

2016-06-17 23:22 260 查看
一.特点

1.没有用户界面,在后台运行

2.应用退出后,Service还继续运行

3.默认情况下,在应用的主线程运行

4.应用重新启动,可以继续调用前面启动的Service

二.分类

1.本地服务:Service对象和启动者在同一个进程内;进程内通信。

2.远程服务:Service对象和启动者在不同的进程内;进程间通信,通过AIDL(Android接口定义语言 ) 来实现

三.实现

1.普通方式

2.绑定方式

普通方式的启动与停止代码展示:

package com.hanqi.testservice;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;

public class MyService extends Service {
public MyService() {

Log.e("TAG","MyService被构造");
}

//回调方法
//绑定
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}


.service







内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: