简体   繁体   中英

Status bar Notification in android

I want to set a onClickListner for a status bar Notification. How it is possible? Please help. Now i can load a Activity by using the pending intent. I like to set a onClickListner for the notificatioin.

Regards Parvathi

It is not possible to set an OnClickListener for a notification. Because of the way notifications are handled/displayed there is no way to guarantee that the process that created the notification will be running at the time the notification is clicked. This means that any code you wrote to provide click handling may not be running.

If you need click listener style behavior you will have to do it using the PendingIntent: set it to start a Service that runs the logic or to use an Intent that is received by a BroadcastReceiver. This will let you perform activity without requiring a UI.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM