我在 AlarmManager 中启动了一个重复任务,但我怎样才能获得服务中的重复计数。这是代码 MyActivity
mAlarmSender = PendingIntent.getService(MyActivity.this,0, new Intent(MyActivity2.this, AutoBuild.class), 0);
long firstTime = SystemClock.elapsedRealtime();
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
firstTime, 1000 * 5, mAlarmSender);
自动构建
public class AutoBuild extends Service {
private String[] infos;
private Intent mIntent;
private String pathStr;
static final String TAG = "AutoBuild";
private int i=0;
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
this.mIntent = intent;
return START_STICKY;
}
@Override
public void onCreate() {
mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
printData(i);/**print result*/
i++;/*count ++*/
AutoBuild.this.stopSelf();/*stop service */
}
private void printData(int i) {
Log.i(TAG, i + "");
}
@Override
public IBinder onBind(Intent intent) {
return mBinder;
}
private final IBinder mBinder = new Binder() {
@Override
protected boolean onTransact(int code, Parcel data, Parcel reply,
int flags) throws RemoteException {
return super.onTransact(code, data, reply, flags);
}
};
}
i 的值始终为 0:Alarmanage 重复时是否可以更改此值