2)SystemServer (属于APP层)
文件:mokoid-read-only/apps/LedTest/src/com/mokoid/LedTest/LedSystemServer.java
view plaincopy to clipboardprint?
package com.mokoid.LedTest;
import com.mokoid.server.LedService;
import android.os.IBinder;
import android.os.ServiceManager;
import android.util.Log;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
public class LedSystemServer extends Service {
//注意这里的Service是APP中的概念,代表一个后台进程。注意区别和Framework中的service的概念。
@Override
public IBinder onBind(Intent intent) {
return null;
public void onStart(Intent intent, int startId) {
Log.i("LedSystemServer", "Start LedService...");
/* Please also see SystemServer.java for your interests. */
LedService ls = new LedService();
try {
ServiceManager.addService("led", ls); //将LedService添加到ServiceManager中
} catch (RuntimeException e) {
Log.e("LedSystemServer", "Start LedService failed.");
}
}
}