Android: don't call QtLoader.finish() on null activity/service

Task-number: QTBUG-115016
Change-Id: Ia7cf066261bd0bb17d67423b5edf7b72ec33d577
Reviewed-by: Janne Juntunen <janne.juntunen@qt.io>
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Petri Virkkunen <petri.virkkunen@qt.io>
(cherry picked from commit 84f0b483b5befb2fef070b5c05c17e1fcd7dac1d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Assam Boudjelthia 2023-12-18 16:12:50 +02:00 committed by Qt Cherry-pick Bot
parent c27163cd7d
commit b9f5b892d4
2 changed files with 12 additions and 1 deletions

View File

@ -44,6 +44,10 @@ class QtActivityLoader extends QtLoader {
} }
private void showErrorDialog() { private void showErrorDialog() {
if (m_activity == null) {
Log.w(QtTAG, "cannot show the error dialog from a null activity object");
return;
}
Resources resources = m_activity.getResources(); Resources resources = m_activity.getResources();
String packageName = m_activity.getPackageName(); String packageName = m_activity.getPackageName();
AlertDialog errorDialog = new AlertDialog.Builder(m_activity).create(); AlertDialog errorDialog = new AlertDialog.Builder(m_activity).create();
@ -57,6 +61,10 @@ class QtActivityLoader extends QtLoader {
@Override @Override
protected void finish() { protected void finish() {
if (m_activity == null) {
Log.w(QtTAG, "finish() called when activity object is null");
return;
}
showErrorDialog(); showErrorDialog();
m_activity.finish(); m_activity.finish();
} }

View File

@ -36,7 +36,10 @@ class QtServiceLoader extends QtLoader {
@Override @Override
protected void finish() { protected void finish() {
m_service.stopSelf(); if (m_service != null)
m_service.stopSelf();
else
Log.w(QtTAG, "finish() called when service object is null");
} }
@Override @Override