마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

한 어플리케이션에서 푸시 알림이 여러번 왔을때 알림을 누를때마다 새로운Activity로 세팅

0 추천

안녕하세요 GCM 푸시 Client 구현중이 있습니다.

푸시 알림이 처음와서 푸시를 클릭하면 해당 Activity로 이동을 잘합니다.

그리고 새로운 이벤트가 발생하여  다른 푸시가 발생되었을때 

기존 푸시에 왔던 Activity를 죽이고 새로운 데이터가 세팅된 Activity를 띄워야하는데

클릭했을때 새로운 Activity가 안뜨네요... (기존 Activity랑 새롭게 떠야하는 Activity는 동일 Class로 된 Activity 입니다 )

기존 Activity가 떠 있는 상태에서 알림  계속 뜨는데 클릭이후 해당 새로운 Activity로 이동을 안하고 기존 Activity가 그대로 

화면에 존재합니다. 이문제는 어떻게 하면 좋을까요....PendingIntent 플래그를 바꾸어도 새로운 화면으로 안나오네요

PendingIntent.FLAG_ONE_SHOT

PendingIntent.FLAG_CANCEL_CURRENT 

PendingIntent.FLAG_NO_CREATE

PendingIntent.FLAG_UPDATE_CURRENT

플래그를 바꿔가면서 해줘도 안되네요...

소스코드는 아래와 같습니다.

public class GcmIntentService extends IntentService{
	   public static final int NOTIFICATION_ID = 1;
	 
	   public GcmIntentService(){
	      super("GcmIntentService");
	   }
	 
	   @Override
	   protected void onHandleIntent(Intent intent){
	      Bundle extras = intent.getExtras();
	      GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);
	      // The getMessageType() intent parameter must be the intent you received
	      // in your BroadcastReceiver.
	      String messageType = gcm.getMessageType(intent);
	 
	      if (!extras.isEmpty()){ 
	         if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)){
	            sendNotification("Send error: " + extras.toString(),"");
	         }else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)){
	            sendNotification("Deleted messages on server: " + extras.toString(),"");
	            // If it's a regular GCM message, do some work.
	         }else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)){
	            String msg = intent.getStringExtra("msg");
	            String erp_id = intent.getStringExtra("erp_id");
	            String encoding1 = null ;
	            String encoding2 = null ;
	            try {
					encoding1 = URLDecoder.decode(msg,"UTF-8");
					encoding2 = URLDecoder.decode(erp_id,"UTF-8");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
	            // Post notification of received message.
//	            sendNotification("Received: " + extras.toString());
	            sendNotification(encoding1,encoding2);


				 Log.d("GcmIntentService", "호출1");
	            
	         }
	      }
	      // Release the wake lock provided by the WakefulBroadcastReceiver.
	      GcmBroadcastReceiver.completeWakefulIntent(intent);
	   }
	 
	   // Put the message into a notification and post it.
	   // This is just one simple example of what you might choose to do with
	   // a GCM message.
	   private void sendNotification(String msg,String erp_id){
	      NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
		   Intent intent = new Intent(getApplicationContext(), ActivityNotification.class);
		   intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
		   intent.putExtra("msg", msg);
	       intent.putExtra("erp_id", erp_id);


//		   PendingIntent.FLAG_UPDATE_CURRENT
	      PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
	      NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).setSmallIcon(R.drawable.ic_launcher)
	                                                                                .setContentTitle("알림")
	                                                                                .setStyle(new NotificationCompat.BigTextStyle().bigText(msg))
	                                                                                .setContentText(msg)
	                                                                                .setAutoCancel(true)
	                                                                                .setVibrate(new long[] { 0, 500 });
	      mBuilder.setContentIntent(contentIntent);
	      mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
	      

	   }
	}

고수님들 도와주십쇼...

감사합니다.

한방에끝내요 (160 포인트) 님이 2015년 7월 1일 질문

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...