We know that the Ubuntu mobile platform is a single-tasking system. A user can open many apps, but only the foreground app is an app that can be running. Many applications pushed to the background are stored in memory. If there are many such applications in existence, memory will be exhausted sooner or later. The operating system can select some applications to be killed to ensure proper operation of the system. In order to be able to guarantee the status of the application at exit, we have designed an interface such as Statesaver on the Ubuntu system. It can be used to help us save the status of an app in an unhealthy exit so that it resumes its previous state after the app restarts.
Referring to the design of the article, we designed the following code:
Import QtQuick 2.0import ubuntu.components 1.1/*! \brief MainView with a Label and Button Elements.*/mainview {id:mainview//ObjectName for functional testing purp OSes (AUTOPILOT-QT5) objectName: "MainView"//note! ApplicationName needs to match the "name" field of the click Manifest ApplicationName: "Statesaver.ubuntu"/* Th Is property enables the application to change orientation when 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 {id:mainpage title:i18 n.tr ("State saver") Rectangle {id:root anchors.fill:parent color: "Green" Statesaver.properties: "Color" Column {spacing:units.gu (2) Anchors.center In:parent Button { Anchors.horizontalCenter:parent.horizontalCenter text: "Change Color" onclicked: {Root.color = Qt.rgba (Math.random (1), Math.random (1), Math.random (1), 1); }} Button {Anchors.horizontalCenter:parent.horizontalCenter Text: "Quit" OnClicked:Qt.quit ()}}}}
To run our application:
We can press "Changecolor" to alter our colors. When we press "quit", exit the app. However, after we restart our app, the color when the app exits is still green when the color is initialized. That is what we use in the program:
Statesaver.properties: "Color"
Did not help us to save our colors.
Next, we re-run our application and adjust the colors we need, such as blue:
We open our terminal on the computer and enter the following command:
We can see that our application has been ruthlessly killed. We open our app again on the phone. We can see that after the app starts, the color is the last time it was killed in the blue, not the green that was applied in the initialization. In other words, the value of the color is saved when the process is killed.
We can refer to the article to save multiple properties.
The code for the entire application is: Git clone https://gitcafe.com/ubuntu/statesaver.git
Use Statesaver to save our data when an abnormal exit is applied