如何点击通知文本关闭应用程序而不打开其他活动

问题描述:

I am developing a flashLight app and I faced a problem in notification which is : When I press the notification text I want to turn of flash and close the whole app , How can I modified the notification method to do that ??

please help and thanks in advance .

this is my notification method 
  
 

public void getNotification()
    {
        Intent intent = new Intent();
        PendingIntent pIntent = PendingIntent.getActivity(this, 0, intent , PendingIntent.FLAG_CANCEL_CURRENT);

        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setContentIntent(pIntent)
                .setContentTitle(res.getString(R.string.notification_title))
                .setContentText(res.getString(R.string.notification_text))
                .setSmallIcon(R.drawable.icon)
                .setAutoCancel(true)
                .setTicker(getString(R.string.notification_ticker_msg));
        // Build the notification:
        Notification notification = builder.build();

        // Get the notification manager:
        NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);

        // Publish the notification:
        final int notificationId = 0;
        notificationManager.notify(notificationId, notification);
    }





我的尝试:



我试图制作anthor活动并在其中放置和关闭app方法,但它不起作用。



What I have tried:

I tried to make anthor activity and put turn of and close app methods in it, but it does not work .

它不是一个好的练习你想要达到的目标。但是你会从这里得到一些想法:

android - 如何通过点击通知关闭我的应用程序的任何活动? - 堆栈溢出 [ ^ ]
Its not a good practice what you want to achieve. But you will get some idea from here:
android - How to close any activity of my application by clicking on a notification? - Stack Overflow[^]