프로그래밍/Android

BroadcastReceiver 에서 AlertDialog 띄우기 등.

LucidasH 2011. 7. 21. 11:35


BroadcastReceiver 나  Service 등과 같이 Activity 가 아닌 곳에서

실제 Activity의 context 를 가지고서  startActivity 등의 행동을 하기 위해서는  그냥 Intent를 만들어 전달하는 것이 아니라,   PendingIntent를 이용해야만 한다.


   Intent i = new Intent( context , PurposeActivity.class);
   PendingIntent pi = PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_ONE_SHOT );

   try {
        pi.send();
   } catch( Exception e ) {}

 와 같이 하면  할 수 있다.