T
T
twobomb2017-09-15 16:56:03
Java
twobomb, 2017-09-15 16:56:03

(Question for android gurus) Why doesn't the curtain collapse when you click on the button in the custom notification?

In general, I made my big Notification, added a button there that opens the activity with settings, but the problem is that I click on the button, the activity opens in the background, but the curtain does not collapse, it must be manually collapsed. How can I make it collapse when the button in the notification is clicked?
The handler is made like this, there is a class

public static class MyButtonListener extends BroadcastReceiver {
        @Override
            public void onReceive(Context context, Intent intent) {
            switch (intent.getStringExtra("element")){
                case "SETTINGS":
                    intent = new Intent(context,SettingsActivity.class);
                    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);//МОЖЕТ НУЖНО ДРУГОЙ\ДОПОЛНИТЕЛЬНЫЙ ФЛАГ?

                    context.startActivity(intent);//ВОТ ТУТ ВЫЗЫВАЕТСЯ АКТИВИТИ С НАСТРОЙКАМИ
                    break;
                case "EYE":
                    break;
                case "SOUND":
                    break;
            }
        }
    }

The class is in the manifest
<receiver android:name=".ServiceNotification$MyButtonListener" />

I hang it on the settings button like this (when building Notification)
Intent myIntent = new Intent(this, MyButtonListener.class);
                    myIntent.putExtra("element","SETTINGS");
                    PendingIntent pendingMyIntent = PendingIntent.getBroadcast(this, 0, myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                    expandedView.setOnClickPendingIntent(R.id.notif_btn_settings, pendingMyIntent);

Well, or perhaps offer your own version of processing Notification buttons.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
twobomb, 2017-09-15
@twobomb

Got it! I'll answer my own question, maybe someone will need it.
To set an event on your buttons in your custom Big Notification. This design should be used.

Intent tt = new Intent(this, SettingsActivity.class);
                    TaskStackBuilder ss = TaskStackBuilder.create(this);
                    stackBuilder.addParentStack(MainActivity.class);
                    stackBuilder.addNextIntent(tt);
                    PendingIntent rr = stackBuilder.getPendingIntent(
                            0, PendingIntent.FLAG_UPDATE_CURRENT);
                    expandedView.setOnClickPendingIntent(R.id.notif_btn_settings, rr);
//notif_btn_settings - ид Кнопки, expandedView это мой RemoteViews

You should definitely use TaskStackBuilder otherwise the activity will open, but the curtain will not close itself!
You also don't need the MyButtonListener receiver class, the FLAG_ACTIVITY_NEW_TASK flag, and so on...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question