#1 2016-01-06 22:18:40

datadon
Member
Registered: 2015-04-23
Posts: 108

Proper shutdown

What would you say is the proper way to shutdown an app so that it is not running in the background and not using memory.

What action should be used in a button?

Offline

#2 2016-01-06 22:30:21

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Proper shutdown

Hello Donald,

If our application is builded by Cordova, then we can use something like this in Android:

StartJS
  navigator.app.exitApp(); 
EndJS

However, the above code do not work in any other platform. And why this piece of code is not added into App Builder like other actions at least to use it for Android? Because in fact we no need to worry about close applications at all, Donald. It's responsible of the system to maintain their memory clean and to close or not this or this other application when they wanted or needed.

What we can do instead is to take care about some application's events like Pause and Resume. This is something called "the application life cycle". If you think a little, Donald, what number of applications have "Close" or "Exit" button in the Android or other mobile world? This is something common in Windows, but not in mobile systems, in which the user simply go from one application to another, without care about how the system manages the resources.

Offline

#3 2016-01-07 04:07:44

datadon
Member
Registered: 2015-04-23
Posts: 108

Re: Proper shutdown

Ok that was my original thought.  But I sent my tipcalc app to my friend and the only comment I got back was how does this shut down and clear from memory.   I know if I just use the back button on the phone the app goes away but I think it is still running as it looks the same with data when I go back to it. 

So I am unknowledgeable here.   I know you have an Exit control, but I do not think it is the same. 

Any more thoughts are appreciated.

Appended

Ok I open the app with an exit button and then open another app and then go back to orig app and input data is still there so it must remain open.

However if I look in settings/apps/running I do not see any open apps that I opened. 

Still confusing

Last edited by datadon (2016-01-07 04:29:48)

Offline

#4 2016-01-07 04:56:06

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Proper shutdown

Hello Donald,

It's a bit confusing because we are thinking in Windows applications, and Windows applications have exit buttons, or, at least, have a "cross" in the title bar which allow us to close the applications. But the things rules in a different way in mobile operating systems.

Basically we can control the application life cycle using the "Pause" and "Resume" events. For example, if you want that the data dissapear when the applications is put in background, use the "Pause" event to clean the data you wanted.

When our application enters in background because the user just want to use other application, what the operating system does: close the application, maintain it in memory, is something out of our scope and we no need to worry about.

Take a look at this topic in the Phonegap Google Group.

Offline

#5 2016-01-07 16:38:55

datadon
Member
Registered: 2015-04-23
Posts: 108

Re: Proper shutdown

Ok, I checked all the links and actually found a good one on Quora about why android apps don't have exit buttons.

I think I get it now.  Android actually wants it that way.  The app is paused and android needs more memory it will close the least important app, usually the one not used for the longest time.  Very interesting.    There are a few exceptions, GPS is one.

Thanks for all the help.  I know more than I did when I asked the question so not a bad day overall.

Offline

#6 2016-01-07 16:47:31

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Proper shutdown

Hello,

datadon wrote:

I think I get it now.  Android actually wants it that way.  The app is paused and android needs more memory it will close the least important app, usually the one not used for the longest time.  Very interesting.    There are a few exceptions, GPS is one.

That's the point! Furthermore an application can be killed by the system but their capture continue appearing into the application's list, so the user can change to that application again. Apparently the application is not terminated but we can only view an image capture of the application, so in fact the system can kill it and leave such capture only.

For this reason the "Pause" and "Resume" events exists: we can always save some application state in the "Pause" event (when our application enters in background) and then use the "Resume" event to restore the previously saved state. No matter if the application is killed or not after the "Pause" event.

A possible scenario can be the below one:

1º We start our application, which consists in a form to send information to our server.

2º We start to fill the form with some data, but, at that moment we receive an incomming call.

3º We go into the telephone application, so our application enters in background mode.

At this step we can use the "Pause" event in order to save the already filled form fields.

4º The phone call is not to large, so we just hangup and go back into our application.

At this point, if our application is not killed by the system, the "Resume" event is executed, so we can restore the state of our form in order to never loss the information previously provided by the user.

Now supose this other way in the same scenario:

4º We need to open others applications while we are answering the phone call.

5º The system are low of resouces, so begin to kill old applications to allow the new ones.

6º The phone call ends and we want to go back into our application to continue to fill the form.

At this point, if our application has been killed by the system before, then the "Resume" event is never executed. However, we save something previously in the "Pause" event, so, in any case, even if our application is restarted by the system or their "Resume" event is fired, we can fill our app's form with the previously saved data.

In fact this is what the user expect: they do not expect to fill the form from scratch again, and they don't understand if the applications has been paused, enters in background or killed by the system. They just expect the entered information is not loss and then no need to be provided again.

If we close our application by ourself we broke the above "circle", and, for example, no matter what the system shown in the applications' list: if we close the application, then the system always need to execute it from scratch, which is something more expensive compared to simply "resume" the application.

Offline

#7 2016-01-09 17:15:26

David
Admin
From: Alcobendas, Madrid, Spain
Registered: 2015-04-21
Posts: 1,660
Website

Re: Proper shutdown

Hello Donald,

I think you mention above something about the Exit action and I do not answer it. So here is:

The Exit action can be used to exit the current script block, without execute any next possible actions.

Offline

Board footer

Powered by FluxBB


Copyright ©2018 DecSoft. All rights reserved.