How to prevent the application from terminating when I click the Назад button in Qt on Android ? Simply, my application connects to the server, and I need the application not to terminate right away.
- Always build the application based on the fact that it can be "nailed" at any time by the system. This is the very nature of Android OS. - Eugene Krivenja
2 answers
It is necessary to generate service from the application. Here is a translation from the official documentation :
Starting from Qt 5.7, you can now create Android services using Qt. A service is a component that runs in the background and does not have a user interface. It is needed to perform lengthy operations, such as logging GPS data or waiting for alerts from social networks. The service continues to work even after the application that launched it has been closed.
You cannot prevent the application from terminating. The maximum is to grab the Back button and ignore the press. But the Home button is not overridden or intercepted.
If your request to the server should continue, you need to implement it not in the Activity, but in the Service. Service, unlike Activity, when moving to another application will not be unloaded from memory and will continue to work.