當調用與報警管理類我得到的錯誤說:如何通過Alarm Manager傳遞構造函數?
「無零個構造法」有沒有辦法通過構造函數或對象與AlarmManager或者是我唯一的選擇只是增加一個方法沒有構造函數?
(不使用串行化方法)
編輯:
(從服務類被調用) 報警管理器代碼:
public void startCollector(){
final int LOOP_REQUEST_CODE = 4;
Intent i = new Intent(getApplicationContext(),DataCollector.class);
PendingIntent sender = PendingIntent.getBroadcast(getApplicationContext(),LOOP_REQUEST_CODE,i,0);
long firstTime = SystemClock.elapsedRealtime();
firstTime += 3*1000;
Log.v("SPAM","Set");
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 1000, sender);
}
被叫類代碼:
package com.project.backgroundprocesstest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class DataCollector extends BroadcastReceiver{
LocationControl lc = null;
public DataCollector(){
}
public DataCollector(Context context){
lc = new LocationControl(context);
}
@Override
public void onReceive(Context context,Intent intent){
collectData(context);
}
private void collectData(Context context){
HttpConnect conn = new HttpConnect();
try {
if (lc.getLocation() != null)
Log.v("SPAM", lc.getLocation());
}catch (NullPointerException e){
}
Log.v("SPAM", "SEND");
}
}
目標:
我想打電話給collectData()從同一DataCollector實例的每個〜5分鐘,以收集數據,並顯示在該通知。
請詳細解釋「用Alarm Manager調用課程」的含義。例如,您可能會發布[mcve]。 – CommonsWare
更新了說明 – atanti