android 點擊通知欄返回應用 ,非啟動一個新Activity


 

再使用如下的 Intent 設置:

Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);

就可以返回當前 Activity 而不是重新運行了一個 activity。

復制代碼
public Notification createNotification() {
        Notification nf = new Notification(android.R.drawable.stat_sys_download, "正在為您下載...", System.currentTimeMillis());

        nf.flags = Notification.FLAG_ONGOING_EVENT;
        nf.contentView = new RemoteViews(getPackageName(), R.layout.notification_download);
        setNotificationInfo(nf, 0, "..M", null, true);

        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        
        nf.contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

        return nf;
    }
復制代碼

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM