close app from notification

0

I want to finish with the app by clicking the notification, my current code launches an activiti but I want to directly finish the app

private void notificacion (String radio){

    NotificationCompat.Builder mBuilder;
    NotificationManager mNotifyMgr =(NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE);

    //int icono = R.mipmap.ic_launcher;
    Intent i=new Intent(MainActivity.this, MainActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, i, 0);

    mBuilder =new NotificationCompat.Builder(getApplicationContext())
            .setContentIntent(pendingIntent)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentTitle("Anime Fm 2")
            .setContentText("Reproduciendo "+radio+" en segundo plano")
            //.setVibrate(new long[] {100, 250, 100, 500})
            .setAutoCancel(true);
    if (mediaPlayer!=null && mediaPlayer.isPlaying()){
        mNotifyMgr.notify(1, mBuilder.build());
    } else {
        mNotifyMgr.cancel(1);
    }
}
    
asked by Djdadi43 06.10.2017 в 18:20
source

1 answer

1

You have to add to your part of the code where you want it to be closed. The finish () method.

finish().

When creating your Intent:

Intent i=new Intent(MainActivity.this, MainActivity.class);  
i.setAction("fin");  //Agregue una accion

In onCreate of your Activity:

try {
String s = getIntent().getAction();

if (s.equals("fin")) {
    finish();
}
}catch(Exception e){

}
    
answered by 06.10.2017 / 20:26
source