2013-10-29 4 views
2

Android에서 알림과 관련하여 이상한 문제가 있습니다. I 알림이 방법을 만드는거야 :앱이 백그라운드에 있지 않을 때 Android 알림

 NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
     Intent notificationIntent = new Intent(context, MyClass.class); 
     notificationIntent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
     notificationIntent.putExtra("data", value); 

     PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
     Notification updateComplete = new NotificationCompat.Builder(context) 
       .setContentTitle(title) 
       .setContentText(msg) 
       .setTicker(title) 
       .setWhen(System.currentTimeMillis()) 
       .setContentIntent(contentIntent) 
       .setDefaults(Notification.DEFAULT_SOUND) 
       .setAutoCancel(true) 
       .setSmallIcon(R.drawable.icon_notifications) 
       .build(); 

     notificationManager.notify(100, updateComplete); 

응용 프로그램이 실행되는 (또는 TEH 배경) 및 했나 사용자가 알림을 클릭, 모든 작동합니다. onNewIntent이 호출되고 데이터가 추가 항목에 있습니다. 그러나 앱이 실행 중이 아니거나 백그라운드에서 실행 중이 아니면 onNewIntent()이 호출되지 않습니다. 나는 을 getIntent()을 사용하여 onCreate()에서 얻으려고했지만, 추가 비용이 없습니다. 앱이 이미 실행되고 있지 않을 때 추가 정보를 얻을 수 있습니까?

내 활동은 모두 singleTop입니다.

답변

0

의도에 대한 몇 가지 동작을 설정 시도해보십시오

notificationIntent.setAction(Long.toString(System.currentTimeMillis())); 

그런 다음에서 onCreate에 엑스트라를 얻을.

PendingIntent.FLAG_UPDATE_CURRENT0으로 바꿀 수도 있습니다.

관련 문제