Qt World Summit: Submit your Presentation

Android Notification problem app close

  • I'm currently trying to set some notification using Qt 5.7 for Android. The notification work fine when the App is open and when the App is on the background, but the notification stop working when Android clear the RAM.

    Here my code, notification.cpp

    #include "notificationclient.h"
    #include <QDebug>
    #include <QtAndroidExtras/QAndroidJniObject>
    NotificationClient::NotificationClient(QObject *parent)
        : QObject(parent)
        connect(this, SIGNAL(notificationChanged()), this, SLOT(updateAndroidNotification()));
    void NotificationClient::setNotification(const QString &notification)
        if (m_notification == notification)
        m_notification = notification;
        emit notificationChanged();
    QString NotificationClient::notification() const
        return m_notification;
    void NotificationClient::updateAndroidNotification()
        QAndroidJniObject javaNotification = QAndroidJniObject::fromString(m_notification);

    notification.java :

    package com.loayza.medit;
    import android.app.Notification;
    import android.app.NotificationManager;
    import android.content.Context;
    public class NotificationClient extends org.qtproject.qt5.android.bindings.QtActivity
        private static NotificationManager m_notificationManager;
        private static Notification.Builder m_builder;
        private static NotificationClient m_instance;
        public NotificationClient()
            m_instance = this;
        public static void notify(String s)
            if (m_notificationManager == null) {
                m_notificationManager = (NotificationManager)m_instance.getSystemService(Context.NOTIFICATION_SERVICE);
                m_builder = new Notification.Builder(m_instance);
                m_builder.setContentTitle("Tratamiento !");
            m_notificationManager.notify(1, m_builder.build());

    What can I do to keep my App running on the background even after Android close it ?

    Thanks for your help

Log in to reply