Android 实例展现如何不同程序间的Serivce调用
2010-09-15 00:10:00 来源:WEB开发网}
};
@Override
public void onCreate() {
super.onCreate();
Log.d("DemoService", "Service onCreate");
nm = (NotificationManager) getSystemService(Service.NOTIFICATION_SERVICE);
Notification n = new Notification(android.R.drawable.stat_notify_more,
"demo Service start", System.currentTimeMillis());
Intent praentA = new Intent(this, ServiceActivity.class);
PendingIntent pi = PendingIntent.getActivity(this, 0, praentA, 0);
n
.setLatestEventInfo(this, "Demo Running",
"com.shinestudio.demo.demoservice", pi);
n.flags = Notification.FLAG_ONGOING_EVENT;
nm.notify(0x1111, n);
}
@Override
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
Bundle b = intent.getExtras();
if (b != null) {
pushData1 = b.getString("pushdata1");
pushData2 = b.getString("pushdata2");
}
}
@Override
public void onRebind(Intent intent) {
Log.d("DemoService", "Service onRebind");
super.onRebind(intent);
}
@Override
public boolean onUnbind(Intent intent) {
Log.d("DemoService", "Service onUnbind");
return super.onUnbind(intent);
}
@Override
public void onDestroy() {
Log.d("DemoService", "Service onDestory");
nm.cancel(0x1111);
super.onDestroy();
}
@Override
public IBinder onBind(Intent arg0) {
return dBinder;
}
}
ServiceActivity
package com.shinestudio.demo.service;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Intent;
更多精彩
赞助商链接