Push Notification opening new copy of the app?

Asked

Viewed 26 times

1

I’m trying to create a push notification but push always opens a copy of the application and I want it to open my application again if it is in the background. How to do this ?

I’m trying like this

public class SendNotification {

    public SendNotification(Context context, String title, String tickerText, String message, String url) {
        NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        PendingIntent contentIntent;

        Intent intent = new Intent(context, SplashView.class);

        Bundle bd = new Bundle();
        bd.putString("url", url);
        intent.putExtras(bd);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |
                        Intent.FLAG_ACTIVITY_SINGLE_TOP |
                        Intent.FLAG_ACTIVITY_NEW_TASK |
                        Intent.FLAG_ACTIVITY_NO_HISTORY
                       );

        contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
                .setSmallIcon(R.drawable.logo)
                .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
                .setTicker(tickerText)
                .setContentTitle(title)
                .setShowWhen(true)
                .setWhen(System.currentTimeMillis())
                .setContentText(message);

        mBuilder.setContentIntent(contentIntent);


        Notification notification = mBuilder.build();
        notification.flags |= Notification.FLAG_AUTO_CANCEL;
        notification.vibrate = new long[]{150, 300, 150, 600};
        mNotificationManager.notify(AndroidSystemUtil.randInt(), notification);

    }
}
  • @ramaral and how do I close the current task and reopen it as if it were a Reload of my app ? I’m trying Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK. But I haven’t had any results yet. thanks

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.