안드로이드 개발 질문/답변
(글 수 45,052)
2009.08.27 13:15:57
dualwield 님 답변 감사합니다^ ^
먼저 링크걸어주신분의 블로그를 참고하고 이해가 되지않아서 위의 글을 쓰게되었습니다^ ^;;
해당 receiver로 값을 전달을 어떻게 해야하는지가 나와있지 않아서요.^ ^;;
2009.08.27 14:29:49
[TestMain.java]
Toast mToast;
PendingIntent sender;
AlarmManager am;
public static String g_strValue1 = "";
public static String g_strValue2 = "";
public void onResume()
{
super.onResume();
if(조건에 맞을때..)
{
// AlarmManager
Intent intent = new Intent(TestMain.this, AlarmService_Service.class);
sender = PendingIntent.getBroadcast(TestMain.this, 0, intent, 0);
long firstTime = SystemClock.elapsedRealtime();
firstTime += 60*1000;
//Alarm을 설정한다. 60초마다 반복.
am = (AlarmManager)getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, 60*1000, sender);
}
}
public void onPause()
{
super.onPause();
//서비스 종료
if(am!=null)
{
try
{
am.cancel(sender);
}
catch(Exception e)
{
}
}
}
[AlarmService_Service.java]
public class AlarmService_Service extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)//10초 마다 여기로 들어온다.
{
Toast.makeText(context, "text", 1000).show();
Log.d("Toast", "T O A S T");
Log.d("TestMain. g_strValue1 : ", TestMain. g_strValue1 );
Log.d("TestMain. g_strValue2 : ", TestMain. g_strValue2 );
//TCPClient t = new TCPClient();
//String recv = t.login(TestMain.g_strTagID, TestMain.g_strTagPW);
}
}