Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QtServiceBase.java
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4package org.qtproject.qt.android;
5
6import android.app.Service;
7import android.content.Intent;
8import android.os.IBinder;
9import android.util.Log;
10
11public class QtServiceBase extends Service {
12 @Override
13 public void onCreate()
14 {
15 super.onCreate();
16
17 // the application has already started, do not reload everything again
18 if (QtNative.getStateDetails().isStarted) {
19 Log.w(QtNative.QtTAG,
20 "A QtService tried to start in the same process as an initiated " +
21 "QtActivity. That is not supported. This results in the service " +
22 "functioning as an Android Service detached from Qt.");
23 return;
24 }
25
26 QtNative.setService(this);
27
28 QtServiceLoader loader = new QtServiceLoader(this);
29 loader.loadQtLibraries();
30 QtNative.startApplication(loader.getApplicationParameters(), loader.getMainLibraryPath());
31 QtNative.setApplicationState(QtNative.ApplicationState.ApplicationHidden);
32 }
33
34 @Override
35 public void onDestroy()
36 {
37 super.onDestroy();
38 QtNative.quitQtCoreApplication();
39 QtNative.terminateQt();
40 QtNative.setService(null);
41 QtNative.getQtThread().exit();
42 System.exit(0);
43 }
44
45 @Override
46 public IBinder onBind(Intent intent) {
47 synchronized (this) {
48 return QtNative.onBind(intent);
49 }
50 }
51}