WEB开发网
开发学院手机开发Android 开发 Android 编写 Service 入门 阅读

Android 编写 Service 入门

 2010-04-09 06:15:00 来源:WEB开发网   
核心提示:package="com.easymorse" android:versionCode="1" android:versionName="1.0">< android:name=".LocalServiceDemoActivity&quo

package="com.easymorse" android:versionCode="1" android:versionName="1.0">

< android:name=".LocalServiceDemoActivity">

android:label="@string/app_name">

android:name="android.intent.category.LAUNCHER">

android:name="CountService">

android:minsdkversion="3">

Acitity代码不再通过startSerivce和stopService启动关闭服务,另外,需要通过ServiceConnection的内部类实现来连接Service和Activity。

package com.easymorse;

import android.app.Activity;

import android.content.ComponentName;

import android.content.Intent;

import android.content.ServiceConnection;

import android.os.Bundle;

import android.os.IBinder;

import android.util.Log;

public class LocalServiceDemoActivity extends Activity {

private ServiceConnection serviceConnection = new ServiceConnection() {

@Override

public void onServiceConnected(ComponentName name, IBinder service) {

countService = (ICountService) service;

Log.v("CountService", "on serivce connected, count is "

+ countService.getCount());

}

@Override

public void onServiceDisconnected(ComponentName name) {

countService = null;

}

};

private ICountService countService;

/** Called when the activity is first created. */

上一页  1 2 3 4 5 6 7  下一页

Tags:Android 编写 Service

编辑录入:coldstar [复制链接] [打 印]
赞助商链接