MainActivity는 모든 조각을 호스팅합니다.알림에서 onNewIntent() 호출
사용자가 Google Cloud Messaging에서받은 알림을 클릭 할 때 특정 부분을 표시해야합니다.
onNewIntent()에서 처리 할 수 있다는 인상을 받았지만 알림을 누르면이 메서드는 실행되지 않습니다.
private void sendNotification(String message, String eventId) {
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent notificationIntent = new Intent(this, MainActivity.class);
notificationIntent.putExtra(Constants.eventIdBundleKey, eventId);
notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|
Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, notificationIntent, 0);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_test)
.setContentTitle(getString(R.string.app_name))
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(message))
.setContentText(message);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
}
여기에 내가받을려고 MainActivity, 및 과정 :
@Override
protected void onNewIntent(Intent intent) {
super.onNewIntent(intent);
if(intent.hasExtra(Constants.eventIdBundleKey)) {
Fragment fragment = GiftsPriceFragment.newInstance(Common.retrieveAppUser(this), null, null);
mFm.beginTransaction().replace(R.id.content_frame, fragment)
.addToBackStack(GiftsPriceFragment.FRAGMENT_TAG).commit();
}
}
어떤 생각
은 여기 내 GcmIntentService에 클래스 내 전송 알림 방법입니다 onNewIntent()가 호출되지 않는 이유는 무엇입니까?
아, 실제로 내 매니페스트에서 singleTop이 필요하고 setIntent()를 호출 한 것처럼 보입니다. 이제 내 유일한 문제는 내가 보낸 문자열을 검색 할 수없는 것입니다, 그것은 onNewIntent() null이 나타납니다? – jwBurnside
해당 문자열을 전혀 검색하지 않습니다. 아마도 hasExtra()가 false를 반환한다고 말할 수 있을까요? – greenapps