Android Question Odd life cycle with both my Galaxy S3's

cyiwin

Active Member
Licensed User
Longtime User
I'm confused about the process life cycle on my S3. When I run my program and my S3 goes to sleep or I push the power button to force sleep mode it goes to:

** Activity (map) Pause, UserClosed = false **
** Activity (map) Create, isFirst = false **
** Activity (map) Resume **

When I Wake the S3 back up it goes to:

** Activity (map) Resume **
** Activity (map) Pause, UserClosed = false **
** Activity (map) Create, isFirst = false **
** Activity (map) Resume **

I tried my wifes Galaxy S3 and it does the same thing.

When I use my Nexus 7 tablet and push the sleep button it does this:

** Activity (map) Pause, UserClosed = false **

When I wake my Nexus 7 up it does this:

** Activity (map) Resume **

The Nexus 7 makes sense to me. I don't understand why Galaxy S3's keep going after pause is called. I also don't understand why waking the S3 makes it go all over the place. Can anyone explain why a device would do that? I wonder how many other devices behave that way? Thanks for reading this!
 

cyiwin

Active Member
Licensed User
Longtime User
What versions of Android are they running?

Galaxy S3's ---> Sprint version 4.1.2
Nexus 7 ---> 4.3

Also I just noticed that it does seems to do this only for GameView programs. It does this for my Game App and Erel's GameViewSmiley and Asteroids Apps. I don't generally run non-GameView Apps but so far all the non-GameView Apps seem to appropriately only call Pause and Resume for all my devices.

Could this be a GameView thing?

Edit: A GameView thing that effects phones but not tablets??
 
Last edited:
Upvote 0

thedesolatesoul

Expert
Licensed User
Longtime User
It depends on the available memory on the device (and how it is managed by the firmware).
On the GS3, it seems it is cycling the activity out of memory when you press the power button, therefore it needs to recreate it when the screen turns on.
The N7 seems to be able to keep it in memory.
 
Upvote 0

cyiwin

Active Member
Licensed User
Longtime User
It depends on the available memory on the device (and how it is managed by the firmware).
On the GS3, it seems it is cycling the activity out of memory when you press the power button, therefore it needs to recreate it when the screen turns on.
The N7 seems to be able to keep it in memory.

Thanks for the input. I do run my app close to the 32 MB mark but I also have this issue with Erel's GameViewSmiley which looks like it doesn't use much memory at all. I'm curious about the firmware management you speak of, maybe there is a setting somewhere on our phones that needs checked or unchecked?

I wonder if someone else can try Asteriods or GameViewSmiley and see if they get different results with their phones?

http://www.b4x.com/android/forum/threads/gameview-create-2d-android-games-part-i.20038/
 
Upvote 0

cyiwin

Active Member
Licensed User
Longtime User
Ahah, yes my app is landscape only. seems like a problem that a lot of people would have. I found a possible solution in a Java Q&A forum. Can this solution be altered to work for Basic4Android?

Check whether your activity has locked the orientation to portrait or landscape, if you have locked the orientation, it will call onCreate() as it changes the orientation before it sleeps and when it wakeup.

you can solve this by adding android:configChanges="orientation" in to activity tag in the manifest.
B4X:
<activityandroid:name=".MainActivity"

android:screenOrientation="portrait"

android:configChanges="orientation"/>
 
Upvote 0

Guardian17

Active Member
Licensed User
Longtime User
I have noticed this same issue with my Galaxy S3 phone, (and not on my Nexus10 tablet), when the app uses a fixed landscape orientation, but adding the one line in the manifest editor did not fix the issue in my case.

By carefully watching what is happening on the screen and in the Log when the GS3 goes to sleep and wakes up, I have noticed that when the device goes to sleep, the "Pause, UserClosed = false" occurs first just after the screen goes dark, then about 3 to 4 seconds later, the "Create" and "Resume" occur, but the screen is dark so nothing is actually seen.

When the device is revived and Resumed, I do notice that the screen does a quick rotation from portrait to landscape (this does not happen on the Nexus), and we know that the Activity Cycle goes through another Pause, Create, and Resume for a screen orientation change.

So, for the GS3, I believe that when the screen goes dark, there is a screen orientation change from landscape to portrait that occurs after the screen is already dark, (note that it is still a Pause, Create, Resume sequence) which then requires the orientation to change back to landscape after the device is revived and the App is Resumed.

That all being said, is it known why there is a difference? Both devices are running Android KitKat V4.4.2. I did first notice this issue when I was working on my fairly large game app, but I then made a very simple App that only puts one label on the screen, and it still does the same thing, so it doesn't seem like it should be a memory issue.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I encountered this issue in the past. It seems like a bug in Android that happens on some devices. It happened in stock Android 4.2.

Try to add this line to the manifest editor (for each activity):
B4X:
SetActivityAttribute(Main, config:changes,  "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize")
 
Upvote 0

Guardian17

Active Member
Licensed User
Longtime User
Tried adding this one long line to the end of the manifest code. When I try to compile, the compilation stops with this information (between the two dashed lines):
------------------------------------
Parsing code. 0.00
Compiling code. 0.02
Compiling layouts code. 0.00
Generating R file. Error
AndroidManifest.xml:19: error: Error parsing XML: unbound prefix
-------------------------------------

In case I made a mistake when I added the line, here is the Manifest code (leaving out the first 3 comment lines):
B4X:
AddManifestText(
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="14"/>
<supports-screens android:largeScreens="true"
    android:normalScreens="true"
    android:smallScreens="true"
    android:anyDensity="true"/>)
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.
SetActivityAttribute(Main, config:changes,  "keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize")

Anything I left out or placed improperly?
 
Upvote 0

Guardian17

Active Member
Licensed User
Longtime User
Erel:
Thanks for the replies, but I get a new error now:
-----------------------------
Parsing code. 0.00
Compiling code. 0.03
Compiling layouts code. 0.00
Generating R file. Error
AndroidManifest.xml:19: error: Error: String types not allowed (at 'configChanges' with value 'keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize').
-----------------------------

It doesn't like compiling with either or both of the last two parameters "screenSize" and/or "smallestScreenSize".
If I omit both of those parameters:
SetActivityAttribute(Main, android:configChanges, "keyboard|keyboardHidden|orientation|screenLayout|uiMode")

the program compiles and runs, but with the same weird outcome as before. Adding either or both parameters to the end, or even omitting the entire string leaving only one of "screenSize" or "smallestScreenSize":
SetActivityAttribute(Main, android:configChanges, "screenSize")
it still yields an error similar to the above.

I even went to the Android Developer site and looked up "android:configChanges" and copied their exact parameter names into my manifest line in case a Control character accidentally got into the line you provided, but I still get the same error when "screenSize" and/or "smallestScreenSize" is included.

Maybe this is too much bother over a specialized bug? I've been trying to iron out the Pause/Create/Resume issue to get my own game App screen to come back exactly as it was when the device goes to sleep, and thinking that this extra orientation change would cause excess/unwanted Resume activity for my App. I've been afraid that the extra Pause/Create/Resume's that occur might cause my own Resume code to do something I won't be able to handle/debug because the screen has gone dark. But I guess I'll just plod ahead and see what happens.

Thanks for your time.
 
Upvote 0

Guardian17

Active Member
Licensed User
Longtime User
--- SOLVED ---

Ahhhhh -- that took care of it. I was using Android-10. Changed it to Android-15 and now the compilation finishes with all of the parameters for the "android:configChanges" present, AND the App only Pauses now -- it does not generate the extra Create and Resume when going to sleep or when waking back up.

I still notice, though, that the screen does do a rotation from portrait to landscape when waking back up, but I assume that whatever these special settings do, the orientation change is ignored in regards to the Activity cycle.

Thank you Erel.
 
Upvote 0
Top