Android实现开机自启动Service
2010-06-22 02:26:00 来源:WEB开发网super.onStart(intent, startId);
}
public IBinder onBind(Intent intent) {
Log.i(TAG, "============> TService.onBind");
return null;
}
public class LocalBinder extends Binder {
public TService getService() {
return TService.this;
}
}
public boolean onUnbind(Intent intent) {
Log.i(TAG, "============> TService.onUnbind");
return false;
}
public void onRebind(Intent intent) {
Log.i(TAG, "============> TService.onRebind");
}
public void onDestroy() {
Log.i(TAG, "============> TService.onDestroy");
notificationManager.cancel(R.string.service_start);
objHandler.removeCallbacks(mTasks);
super.onDestroy();
}
private void showNotification() {
Notification notification = new Notification(R.drawable.icon,
"SERVICE START", System.currentTimeMillis());
Intent intent = new Intent(this, testService.class);
intent.putExtra("FLG", 1);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
intent, 0);
notification.setLatestEventInfo(this, "SERVICE", "SERVICE START",
contentIntent);
notificationManager.notify(R.string.service_start, notification);
}
}
做一个主程序:
package com.testService;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class testService extends Activity {
private Button button01;
private Button button02;
更多精彩
赞助商链接