현재 서비스에서 pendingintent를 사용중입니다. onStartCommand() 에서 intent로 값을 받아 register() 라는 임의로정의한 메서드로 값을 보내고 메서드안에 정의된 pendingintent 로 동적등록 하고 있습니다.
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG,"onStartCommand Called.");
int restart = intent.getIntExtra("restart",0);
switch (restart) {
case 1:
locationList = (HashMap<Integer, PendingIntent>) intent.getSerializableExtra("locationList");
Log.d(TAG, "LocationList : " + locationList);
break;
}
locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
int size = locationList.size();
Log.d(TAG,"Size : " + size);
id = intent.getIntExtra("id",0);
lat = intent.getDoubleExtra("lat",0.0);
lng = intent.getDoubleExtra("lng",0.0);
radius = intent.getFloatExtra("radius", 0);
expiration = intent.getLongExtra("expiration",0);
type = intent.getIntExtra("type",2);
switch (type){
case 0:
register(id, lat, lng, radius, expiration);
break;
case 1:
deleteLocation(id);
break;
}
return Service.START_REDELIVER_INTENT;
}
public void register(int id, double lat, double lng, float radius, long expiration){
Log.d(TAG,"id : " + id + ", lat : " + lat + ", lng : " + lng + ", radius : " + radius + ", expiration : " + expiration);
Intent proximityIntent = new Intent("org.jsb.busgod.busgod");
proximityIntent.setAction("org.jsb.busgod.busgod");
proximityIntent.putExtra("id",id);
pendingIntent = PendingIntent.getBroadcast(this,id,proximityIntent,PendingIntent.FLAG_CANCEL_CURRENT);
locationManager.addProximityAlert(lat,lng,radius,expiration,pendingIntent);
locationList.put(id, pendingIntent);
}
여기서는 pendingintent에 들어간 값을 관리하기 위해서 따로 hashmap 을 정의해서 Integer,pendingintent 로 저장중입니다. 근데 이 구조로 하니까 서비스가 강제로 죽었을때와 핸드폰부팅시 service를 새로시작시킬때 hashmap안에 있는 값을 유지하는게 너무힘듭니다.강제로죽었을때는 리시버로 어떻게 했는데 핸드폰부팅시 서비스를 실행시킬때는 답이 안나오더군요. 그래서 혹시 pendingintent 에 입력된 값을 직접적으로 관리하는방법이 없는지 물어보기 위해서 질문글을 올리게되었습니다. 서비스를 새로 실행시키면 oncreate가 호출되서 계속 hashmap이 초기화되면서 pendingintent 에 입력된값을 관리할수가없습니다. 제발 도와주세요.. 정말 힘이드네요 ㅠㅠ