1

とAndroidのプッシュ通知は、通知のための私の例です: 通知が到着すると、アプリケーションがフォアグラウンド、バックグラウンド、またはフォアグラウンドにここFCM

1.休館かもしれません:通知、アプリのユーザータップが表示されるはずです 主な活動。背景については

2:通知のユーザータップは、アプリケーションが最前面に持っていけばと主な活動に示さなければならないときにアプリケーションが閉じているとき

3.:通知のユーザータップ は、アプリケーションがすべきメインアクティビティが表示されます。

Intent.FLAG_ACTIVITY_SINGLE_TOP &とすると、PendingIntent.FLAG_ONE_SHOTで保留になります。これは期待どおりに動作しますが、ユーザーが通知をタップすると、メインアクティビティのonCreateメソッドは呼び出されません。

private void showNotification() { 

     Intent intent = new Intent(this, DashboardActivity.class); 
     intent.putExtra(AppConstants.SCREEN, screen); 
     intent.putExtra(AppConstants.USER_ID, user_id); 
     intent.putExtra(AppConstants.TABLE_ID, table_id); 
     intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 

     PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 
      PendingIntent.FLAG_ONE_SHOT); 

    Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION); 
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this) 
      .setSmallIcon(getNotificationIcon()) 
      .setContentTitle(getResources().getString(R.string.app_name)) 
      .setContentText(message) 
      .setAutoCancel(true) 
      .setSound(defaultSoundUri) 
      .setContentIntent(pendingIntent); 

    NotificationManager notificationManager = 
      (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 

    notificationManager.notify(0, notificationBuilder.build()); 
    } 

あなたは、コードの上に考える場合、それは、通知のMainActivity(DashboardActivity)ときに、ユーザータップからメソッドを実行する必要があります。

注:アプリケーションがフォアグラウンド/バックグラウンドの場合、新しいものを閉じて開いてはいけません。既存のアプリで更新する必要があります。

あなたは私の状況を理解したいと考えています。前もって感謝します。

答えて

0

ユーザが"Intent.FLAG_ACTIVITY_SINGLE_TOP"と意図している通知をタップすると、インテントのonCreateメソッドは呼び出されません。この質問を読み取るための

@Override 
protected void onNewIntent(Intent intent) {} 

感謝:)

:それは下に書かれた通知のときに、ユーザータップ、メソッドを呼び出します