alarmManager에서 AlarmService_Service.class(BroadcastReceiver)를 거쳐 AlarmAlert.class(alarm 메뉴 띄우는 activity)를 실행하는 구조입니다.
AlarmService_Service에서 AlarmAlert으로 값을 넘겨주는건 잘 되는데 alarmManager에서 AlarmService_Service로는 값이 안넘어가네요; 어디서 놓친건지.. 아시는분 답변 부탁드립니다 ㅋ
--소스--
[main]
private void alarmCheck()
{
SetAlarm sa = new SetAlarm(false);
long alarm = sa.getNextAlarmTime(AddTask.this); // 구해온 알람시간
//Toast.makeText(AddTask.this, Long.toString(alarm), Toast.LENGTH_LONG).show();
Intent intent = new Intent(AddTask.this, AlarmService_Service.class);
intent.putExtra("text", sa.forwordText);
intent.putExtra("dateTime", sa.forwordDateTime);
intent.putExtra("alarmTime", sa.forwordAlarmTime);
PendingIntent sender = PendingIntent.getBroadcast(
AddTask.this,
0,
intent,
0);
AlarmManager am = (AlarmManager)getSystemService(ALARM_SERVICE);
if(alarm != -1)
{
am.set(AlarmManager.RTC_WAKEUP, alarm, sender);
//Toast.makeText(AddTask.this, sa.forwordText + sa.forwordDateTime + sa.forwordAlarmTime, Toast.LENGTH_LONG).show();
}
else // 오늘 울릴 알람이 없다면
am.cancel(sender);
}
[AlarmService_Service.class]
public class AlarmService_Service extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent)
{
Intent notify = new Intent(context, AlarmAlert.class);
notify.putExtra("text", intent.getStringExtra("text"));
notify.putExtra("dateTime", intent.getStringExtra("dateTime"));
notify.putExtra("alarmTime", intent.getStringExtra("alarmTime"));
PendingIntent sender = PendingIntent.getActivity(context, 0, notify, 0);
try
{
sender.send();
}
catch(Exception ex)
{
}
}
}
[AlarmAlert.class]
public class AlarmAlert extends Activity {
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
Intent intentGetContents = getIntent();
requestWindowFeature(android.view.Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
| WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
LayoutInflater inflater = LayoutInflater.from(this);
setContentView(inflater.inflate(R.layout.alarm_alert, null));
final MediaPlayer mp=MediaPlayer.create(AlarmAlert.this, R.raw.alarm);
mp.start();
/*mp.setOnCompletionListener(new OnCompletionListener() {
public void onCompletion(MediaPlayer arg0) {
mp.start();
}
});*/
Calendar c = Calendar.getInstance();
String nowTime = c.get(Calendar.YEAR) + "-" + (c.get(Calendar.MONTH)+1) + "-" + c.get(Calendar.DAY_OF_MONTH);
//TODO
Button buttonClose = (Button)findViewById(R.id.ButtonAlarmAlertClose);
//Toast.makeText(AlarmAlert.this, intentGetContents.getStringExtra("text"), Toast.LENGTH_LONG).show();
buttonClose.setText(intentGetContents.getStringExtra("text"));
buttonClose.setOnClickListener(new OnClickListener(){
public void onClick(View v)
{
mp.stop();
finish();
}
});
}
}
해결했습니다. 값이 안넘어가는게 아니라 AlarmService_Service.class의 onReceive에서 참조되는(참조 변수?) intent를 안드로이드에서 재활용 하기때문에 생기는 문제였습니다. 전에 넘겨준 공백 데이터가 이후에 쓸때도 그대로 사용되기 때문에 계속 다른 값을 집어넣어도 공백이 뜨더군요..; 갱신 되게 만들려면 AlarmService_Service.class나 AlarmAlert에서 db등에 저장되어 있는 해당 데이터를 직접 불러와야 합니다. 혹시 같은 문제로 속썩이고 계시는 분들 참고하세요 ㅎ