Android Question Back Button, Home Button curious phenomena

Roger Daley

Well-Known Member
Licensed User
Longtime User
Hi All

This is a question out of curiosity only. I have a small games App, "Atoms". Most people will have seen one of the many implementations of this game by many developers. Basically atoms are added to squares on a grid of squares until a square reaches critical mass and explodes etc.

In my App the player can exit the game with the Back button, restart the game and continue. This works as normal, no surprises.
If the player exits the game using the Home button and restarts the game it mostly works OK but "Ghost" images of the atoms before exploding remain?

BackButton.jpg HomeButton.jpg

I think the App itself is incidental to the problem but here is a link to the Sourcecode if this can help with the answer. The simple answer of course is "always use the Back button", but it is curious.

Any thoughts?

Regards Roger
 
Last edited:

LucaMs

Expert
Licensed User
Longtime User
But why? This behaviour is completely against the android standards. A app is normally not closed exit by user, only by system.

Because you could open many apps and you must wait the system decide to terminate some app randomly, while your ram become full and your current app is slow.

Furthermore, the user should be able to choose whether to end an app, or not?
In this case, I would not keep in consideration that "android standard" (?).

[I think it is not an Android standard: maybe Google says: "warning: the system could terminate a running app, IF NEEDED"]
 
Last edited:
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
Because you could open many apps and you must wait the system decide to terminate some app randomly, while your ram become full and your current app is slow.
The speed of the current active app is normally independent from the amount of open apps.
The Linux paradigm: unused ram is wasted ram!
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
The speed of the current active app is normally independent from the amount of open apps.
The Linux paradigm: unused ram is wasted ram!

If it is so (I don't know) why take advantage of it?

As user, I don't like that an app I wanted to close is still "active".

Also, why is there a system function which allows you to terminate an app? It would be totally unnecessary, or not?
 
Upvote 0

MaFu

Well-Known Member
Licensed User
Longtime User
If it is so (I don't know) why take advantage of it?

As user, I don't like that an app I wanted to close is still "active".

Also, why is there a system function which allows you to terminate an app? It would be totally unnecessary, or not?
Yes, it is so. And as advantage the app start is much faster because it must not loaded and initialized. And why not, it doesn't matter if the app is loaded or not.
If you don't like it then you should stay away from android because almost all apps have this behaviour. :D
On my Xperia i have two or three dozen apps open without problems and i reboot the device once in a quarter (max.).
The system function to terminate an app is for faulty apps who hangs.
Speculation: if an app has an exit button which completely terminate the app, the programmer may cover misbehaviours :rolleyes:

But now we are completely offtopic.
 
Upvote 0

hibrid0

Active Member
Licensed User
Longtime User
In my understand:
Start App->> Activity_Create (FirstTime = True) -> Activity_Resume
Button Back->>Activity.Finish -> Activity_Pause (Userclosed=True)
Button Home ->> Activity_Pause (Userclosed=False)

And this is from Erel Explanation: from Here

As discussed above Activity_Pause is called every time that the activity moves from the foreground to the background. This can happen because:
1. A different activity was started.
2. The Home button was pressed
3. A configuration changed event was raised (orientation changed for example).
4. The Back button was pressed.

In scenarios 1 and 2, the activity will be paused and for now kept in memory as it is expected to be reused later.
In scenario 3 the activity will be paused, destroyed and then created (and resumed) again.
In scenario 4 the activity will be paused and destroyed. Pressing on the Back button is similar to closing the activity. In this case you do not need to save any instance specific information (the position of pacman in a PacMan game for example).
The UserClosed parameter will be true in this scenario and false in all other. Note that it will also be true when you call Activity.Finish. This method pauses and destroys the current activity, similar to the Back button.

You can use UserClosed parameter to decide which data to save and also whether to reset any related process variables to their initial state (move pacman position to the center if the position is a process variable).
 
Last edited:
Upvote 0
Top