Currently using Qt development program has transplanted with Windows, Linux, and Android three systems, but Android is different from the Windows and Linux, which can minimize the program window to run, the software of the third party call influence, but under the Android system after put the program in the main interface, is in a dormant state, no longer run, so you need to consider under the Android program to make service, so that you can guarantee after the minimizing process, can still keep active in the background,
The sample code is as follows:
Int main (Int arg c, char * argv [])
{
# if defined (Q_OS_ANDROID)
QAndroidService a (arg c, argv);//the news event loop can achieve the Android service
There can be no interface under//Android service because interface can't do without QApplication
//logic to handle some
Return a.e xec ()
# the else
QApplication a(argc, argv);
//logical processing parts, can be the main interface of the
Return a.e xec ();
# endif
}
Although this can be the background, but at the time of application startup, or occupy the main interface, need to have a minimal function, can be invoked through JNI. Java implementation, the sample code as follows: (the specific usage can see Qt on android core programming book)
QAndroidJniObject javaNotification=AndroidJniObject: : fromString (infoMsg);
QAndroidJniObject: : callStaticMethod
Java code is a function called
M_instance. MoveTaskToBack (true);
But there are a few problems:
1, the program in the background, when Android memory, will clean up;
2, this program can not have the interface, if need to interface, in addition to write an app,
CodePudding user response:
You will QApplication QCoreApplication instead give it a try?CodePudding user response:
You can consult: https://doc.qt.io/qt-5/android-services.html# and https://wiki.qt.io/AndroidServices there is create the service method