如何点击通知文本关闭应用程序而不打开其他活动 [英] How do I make clicking on the notificaton text close the app not open other activity

查看:102
本文介绍了如何点击通知文本关闭应用程序而不打开其他活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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[^]


这篇关于如何点击通知文本关闭应用程序而不打开其他活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆