Custom Notification

前端 未结 2 801
后悔当初
后悔当初 2021-01-21 12:29

I would like to know if there is a way of using the notication bar in order to do some operations (onClick), without having an activity being launched/resumed.

for examp

相关标签:
2条回答
  • 2021-01-21 12:50

    Is there any way to implement such a thing?

    Use an appropriate PendingIntent. Instead of calling getActivity(), call getService() or getBroadcast().

    0 讨论(0)
  • 2021-01-21 13:07

    I don't believe this is possible or, at the very least, best practice. It's possible that Android could kill your activity while the Notification is still waiting in the top bar. For example maybe you get a phone call but Android is low on RAM - it kills your activity, thus there's really not a 'current' activity anymore.

    0 讨论(0)
提交回复
热议问题