2015-10-05 146 views
0

我有一個通知,當我點擊它時,打開我的應用程序。但我的應用程序在後臺打開,通知抽屜仍然可見。我的通知本身被取消並刪除,但抽屜仍然存在於所有內容之上。隱藏Notifaction抽屜打開時活動

通知類看起來是這樣的:

public MyNotification(final Context context) { 
    this.context = context; 

    remoteView = new RemoteViews(context.getPackageName(), R.layout.notification); 

    notification = new Builder(context) 
      .setSmallIcon(R.drawable.notification_icon) 
      .build(); 

    notification.flags = Notification.FLAG_NO_CLEAR; 
    notification.priority = Notification.PRIORITY_MAX; 

    remoteView.setOnClickPendingIntent(R.id.container, getIntent(ACTION_OPEN_APP)); 

    notification.bigContentView = remoteView; 

    notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); 
    notificationManager.notify(MY_NOTIFICATION_ID, notification); 
} 

private PendingIntent getIntent(String action) { 
    Intent receiveIntent = new Intent(context, NotificationReceiver.class); 
    receiveIntent.setAction(action); 
    return PendingIntent.getBroadcast(context, 0, receiveIntent, 0); 
} 

我的接收器看起來像這樣:

public class NotificationReceiver extends BroadcastReceiver { 

@Override 
public void onReceive(Context context, Intent intent) { 
    String action = intent.getAction(); 

    if(action.equalsIgnoreCase(AudioPlayerNotification.ACTION_OPEN_APP)) { 

     Intent openAppIntent = new Intent(context, MyActivity.class); 
     openAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 
     context.startActivity(openAppIntent); 
    } 
} 

App in the backtround with notification drawer on top

我也有一個基地活動啓動時刪除通知活動。我錯過了什麼?

回答