0

I create a notification and I want to resume app after click notification. Now when I click notification , a notification dissapear , I want to resume my app (when is minimalize).

  public static void getSynchronizeNotification(Context context, DataResponse dataResponse) {

        Bitmap Largeicon = BitmapFactory.decodeResource(context.getResources(), R.drawable.ic_launcher);
        NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_SYNCHRONIZE_ID);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
        KeyguardManager km = (KeyguardManager) context.getSystemService(KEYGUARD_SERVICE);
        final KeyguardManager.KeyguardLock kl = km.newKeyguardLock("IN");
        kl.disableKeyguard();

        PowerManager pm = (PowerManager) context.getSystemService(POWER_SERVICE);
        PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.ACQUIRE_CAUSES_WAKEUP | PowerManager.FULL_WAKE_LOCK, "SMOK Komunal");
        wl.acquire();
        Uri defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
        NotificationCompat.Builder notificationBuilder = (NotificationCompat.Builder) new NotificationCompat.Builder(context)
                .setCategory(Notification.CATEGORY_PROMO)
                .setSmallIcon(R.drawable.ic_launcher)
                .setContentTitle("Zmiany po synchronizacji...")
                .setStyle(new NotificationCompat.BigTextStyle().bigText(buildNotificationAfterSynchronizeText(dataResponse)))
                .setAutoCancel(true)
                .setSound(defaultSoundUri)
                .setLargeIcon(Largeicon)
                .setContentIntent(pendingIntent)
                .setVibrate(vibratePattern)
                .setLights(Color.GREEN, 2000, 2000)
                .setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
        notificationManager.notify(0, notificationBuilder.build());
//        wl.release();
    }
Alexandre Neukirchen
  • 2,713
  • 7
  • 26
  • 36
Krzysztof Pokrywka
  • 1,356
  • 4
  • 27
  • 50

3 Answers3

0

Edit this line

PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, new Intent(context, MainActivity.class), 0);
alex samsung
  • 110
  • 1
  • 10
  • I don't want to move to MainActivity I want to resume my app (open app in activity which I was) – Krzysztof Pokrywka Jan 26 '17 at 09:57
  • and when I use this it will not finish old activity, when you are in MainActivity and click a notification is open MainActiviti when you press back it will be close MainActivity(which open notification) and resume a MainActivity – Krzysztof Pokrywka Jan 26 '17 at 10:00
  • http://stackoverflow.com/questions/12043671/notification-click-activity-already-open – alex samsung Jan 26 '17 at 10:23
0

I do this and it works :

In MainAcitivity I have :

public static Context currentContext;

Next in all activity in onCreate and onResume and do this :

MainActivity.currentContext = this;

And next when I build a notification I do this :

Intent intent = new Intent(context, MainActivity.currentContext.getClass());
        intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

        PendingIntent pendingIntent = PendingIntent.getActivity(context, (int) System.currentTimeMillis(), intent, PendingIntent.FLAG_UPDATE_CURRENT);
Krzysztof Pokrywka
  • 1,356
  • 4
  • 27
  • 50
0

This works;

<activity android:name=".YourActivity" android:launchMode="singleTop">
Ndivhuwo
  • 280
  • 2
  • 10