WEB开发网
开发学院手机开发Android 开发 Android 开发教程之 Service 详解 阅读

Android 开发教程之 Service 详解

 2010-02-22 16:14:00 来源:WEB开发网   
核心提示:69. }70. }package com.haric.tutorial;import android.app.Notification;import android.app.NotificationManager;import android.app.PendingIntent;import android.app.

69. }

70. }

package com.haric.tutorial;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.app.Service;

import android.content.Intent;

import android.os.Binder;

import android.os.IBinder;

import android.util.Log;

public class TestService extends Service {

private static final String TAG = "TestService";

private NotificationManager _nm;

@Override

public IBinder onBind(Intent i) {

Log.e(TAG, "============> TestService.onBind");

return null;

}

public class LocalBinder extends Binder {

TestService getService {

return TestService.this;

}

}

@Override

public boolean onUnbind(Intent i) {

Log.e(TAG, "============> TestService.onUnbind");

return false;

}

@Override

public void onRebind(Intent i) {

Log.e(TAG, "============> TestService.onRebind");

}

@Override

public void onCreate {

Log.e(TAG, "============> TestService.onCreate");

_nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

showNotification;

}

@Override

public void onStart(Intent intent, int startId) {

Log.e(TAG, "============> TestService.onStart");

}

@Override

public void onDestroy {

_nm.cancel(R.string.service_started);

Log.e(TAG, "============> TestService.onDestroy");

}

private void showNotification {

Notification notification = new Notification(R.drawable.face_1,

"Service started", System.currentTimeMillis);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0,

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

Tags:Android 开发 教程

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