Better_Software_Header_MobileBetter_Software_Header_Web

Find what you need - explore our website and developer resources

Qt on Android: How to restart your application


auto activity = QtAndroid::androidActivity();
auto packageManager = activity.callObjectMethod("getPackageManager",
                                                "()Landroid/content/pm/PackageManager;");

auto activityIntent = packageManager.callObjectMethod("getLaunchIntentForPackage",
                                                      "(Ljava/lang/String;)Landroid/content/Intent;",
                                                      activity.callObjectMethod("getPackageName",
                                                      "()Ljava/lang/String;").object());

auto pendingIntent = QAndroidJniObject::callStaticObjectMethod("android/app/PendingIntent", "getActivity",
                                                               "(Landroid/content/Context;ILandroid/content/Intent;I)Landroid/app/PendingIntent;",
                                                               activity.object(), jint(0), activityIntent.object(),
                                                               QAndroidJniObject::getStaticField<jint>("android/content/Intent",
                                                                                                       "FLAG_ACTIVITY_CLEAR_TOP"));

auto alarmManager = activity.callObjectMethod("getSystemService",
                                              "(Ljava/lang/String;)Ljava/lang/Object;",
                                              QAndroidJniObject::getStaticObjectField("android/content/Context",
                                                                                      "ALARM_SERVICE",
                                                                                      "Ljava/lang/String;").object());

alarmManager.callMethod<void>("set",
                              "(IJLandroid/app/PendingIntent;)V",
                              QAndroidJniObject::getStaticField<jint>("android/app/AlarmManager", "RTC"),
                              jlong(QDateTime::currentMSecsSinceEpoch() + 100), pendingIntent.object());

qApp->quit();

6 Comments

24 - Mar - 2017

ekke

27 - Nov - 2017

JO

9 - Feb - 2018

Le Minh Tu

5 - Mar - 2018

Bogdan Cristea

21 - Oct - 2021

Bel

29 - Jul - 2022

Sebastian Diel