0

So in my app i have notification with pause/play action, when user clicks on the action, notification bar is closing. How can i prevent notification bar from closing upon action click?

I've already done .setAutoCancel(false);

Here I've found a "problem": https://stackoverflow.com/a/53476100/10766642

PendingIntent.getActivity(...) - it closes notification bar.

And yes, I have this lines too:

        PendingIntent btn1 = PendingIntent.getActivity(parent, (int)(Math.random()), intent, PendingIntent.FLAG_UPDATE_CURRENT);
        view.setOnClickPendingIntent(R.id.btn1, btn1);

How can i prevent notification bar closing without using PendingIntent.getService(...) or PendingIntent.getBroadcast(...) ?

danyapd
  • 2,516
  • 1
  • 14
  • 23
  • I think you need foreground service instead. – Zain Jul 01 '21 at 00:03
  • Why are you opening an activity from the notification if you don't want the user to immediately be able to interact with that activity? – ianhanniballake Jul 01 '21 at 00:21
  • @ianhanniballake in this activity I want to interact with notification UI - so in `onCreate` will be something like `setContentView(R.layout.some_view);` and then I want to change image resource, for example `btn1.setImageBitmap(...)` or something like this. How I can interact with UI while using `Service`? – danyapd Jul 01 '21 at 00:31
  • 1
    That doesn't really make much sense. Your activity's layout is completely independent from the notification's UI. You don't need an activity to do anything notification UI related, you can post a notification from any type of component. – ianhanniballake Jul 01 '21 at 01:23

0 Answers0