How to tell if the Qml app is pushed to the background and foreground

Source: Internet
Author: User

In this article, we'll show you how to tell if a QML app is pushed to the background or foreground. We know that in the Ubuntu mobile platform, it is a single application operating system. When an app is pushed to the background, the app is suspended and cannot be run. We sometimes need this logo to determine when our app is in the foreground and when it's in the background.


We use the Ubuntu SDK to create a simple QML application:


Import QtQuick 2.0import ubuntu.components 1.1/*!    \brief MainView with a Label and Button elements.*/mainview {    id:main    //ObjectName for functional testing Purpos ES (AUTOPILOT-QT5)    objectName: "MainView"    //note! ApplicationName needs to match the "name" field of the the Click Ma Nifest    ApplicationName: "Com.ubuntu.developer.liu-xiao-guo.foregrounddetect"/* This property     enables The application to change orientation if the     device is rotated. The default is False.    */    //automaticorientation:true    //Removes the old toolbar and enables new features of the new header.    Usedeprecatedtoolbar:false    Width:units.gu (height:units.gu)    page {        title:i18n.tr (" Foregrounddetect ")        Connections {             target:Qt.application             onactivechanged: {                 Console.log (" Qt.application.active: "+ Qt.application.active);}}}}    

Here, we use the "active" property of the variable qt.application to determine whether an app is pushed to the background or foreground. We run the application with the following results:




When we push the app to the background on the phone, false is displayed and true when we push the app to the foreground.

The source of the entire application is:BZR branch lp:~liu-xiao-guo/debiantrial/foregrounddetect


How to tell if the Qml app is pushed to the background and foreground

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.