Activity.startservice()方式调用service,service接收一个参数,根据这个参数去服务器上读取一些数据下来,在oncreate()中开启一个线程,但需要用到那个参数,但是参数好像不能再oncreate()中接收,新手,大家帮帮忙呗。package com.service;import com.biz.MutualBiz;
import com.bookread.MagaActivity;
import com.bookread.R;import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.Bundle;
import android.os.IBinder;public class MagaService extends Service implements Runnable {
private int id;
private NotificationManager nfm; @Override
public void run() {
MutualBiz biz = new MutualBiz(getApplicationContext());
try {
biz.saveyArtice(id);
} catch (Exception e) {
e.printStackTrace();
} finally {
onDestroy();
}
} @Override
public void onStart(Intent intent, int startId) {
Bundle bundle = intent.getExtras();
id = bundle.getInt("magaId");
super.onStart(intent, startId);
} @Override
public void onDestroy() {
displayNotificationMessage("下载完成");
super.onDestroy();
} @Override
public void onCreate() {
nfm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
Thread thread = new Thread(this);
thread.start();
super.onCreate();
} private void displayNotificationMessage(String message) {
Notification notification = new Notification(R.drawable.icon_down,
message, System.currentTimeMillis()); PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
new Intent(this, MagaActivity.class), 0);
notification.setLatestEventInfo(this, "Background Service", message,
contentIntent); nfm.notify(R.id.app_notification_id, notification);
} @Override
public IBinder onBind(Intent intent) {
return null;
}}