Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Android: App is resumed at lockscreen — Gideros Forum

Android: App is resumed at lockscreen

RickyngkRickyngk Member
edited September 2012 in General questions
Dear,
I'm using 2012.8.4
I've got an issue (run with native, not android player)
+ start game
+ press power button to lock screen
+ press power again to resume
--> notice that game is resumed even though lockscreen is shown (game-screen is not shown)
(http://droidlessons.com/wp-content/uploads/2011/12/android_lockscreen.png)

Have you ever got the same issue before ?

p/s: I tried to use getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); but I think that is not a good solution.

Comments

  • @atilim gave me a hint: http://android-developers.blogspot.com/2011/11/making-android-games-that-play-nice.html

    And the following is my steps:
    + Step1: In activity class, handle event onWindowFocusChanged
    <a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    	public void onWindowFocusChanged(boolean focus)
    + Step 2: send "message" to JNI
    //java
    <a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    public void onWindowFocusChanged(boolean focus)
    {
    	NativeDispatchOnFocusEvent(focus);
    }
     
    //native jni
    int gIsAppFocus = false;
    JNIEXPORT void JNICALL Java_com_giderosmobile_android_MyActivity_NativeDispatchOnFocusEvent(JNIEnv * env, jobject obj, jboolean focus)
    {
    	gIsAppFocus = (focus == JNI_TRUE)?1:0;
    }
    + Step 3: define a C-lua bridge function to read value of gIsAppFocus
    static int IsAppFocus(lua_State *L) 
    {
    	lua_pushboolean(L, gIsAppFocus);
    	return 1; 
    }
    + Step 4: in LUA, when receive event resume, wait until IsAppFocus is true. Example:
    function CGame:onPause()
    	self.mHasPaused = true
    	self.mHasResume = false -- fixed bug: game resume in lock screen on android
    end
     
    function CGame:onResume()
    	self.mHasPaused = false
    	self.mHasResume = true -- fixed bug: game resume in lock screen on android
    end
     
    function CGame:onEnterFrame()
    	if self.mHasPaused == false then
    		-- fixed bug: game resume in lock screen on android
    		if self.mHasResume and  GetDeviceType() == DEVICE_ANDROID then
    			if IsAppFocus() then
    				self.mHasResume = false
    			else
    				return
    			end
    		end
     
    		// update your game here
    	end
    end
    I'd better if we dispatch a LUA event when onWindowFocusChanged is invoked, but I don't know how to do ;)
  • atilimatilim Maintainer
    edited September 2012 Accepted Answer
    Here is another solution. You need to change Activity class only:

    Add these member variables:
    	private boolean mToBeResumed = false;
    	private boolean mLostFocus = false;
    Change onPause as:
    	<a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    	protected void onPause()
    	{
    		mLostFocus = true;
     
    		GiderosApplication.getInstance().onPause();
    		mGLView.onPause();
     
    		super.onPause();
    	}
    Change onResume as:
    	<a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    	protected void onResume()
    	{
    		super.onResume();
     
    		mToBeResumed = mLostFocus;
    		if (!mLostFocus)
    		{
    			mGLView.onResume();
    			GiderosApplication.getInstance().onResume();
    		}
    	}
    Add onWindowFocusChanged function:
    	<a href="http://forum.giderosmobile.com/profile/Override" rel="nofollow">@Override</a>
    	public void onWindowFocusChanged(boolean hasFocus)
    	{
    		super.onWindowFocusChanged(hasFocus);
     
    		mLostFocus = !hasFocus;
    		if (mToBeResumed && hasFocus)
    		{
    			mToBeResumed = false;
    			GiderosApplication.getInstance().onResume();
    			mGLView.onResume();
    		}
    	}

    Likes: fxone

    +1 -1 (+1 / -0 )Share on Facebook
  • Awesome. Thanks for quick support.
  • fxonefxone Member
    edited January 2013
    Hi @Atilim it looks like this solution doesn't work very well on small devices (armv6). I've noticed latency (regardless of the size of the window) at responsiveness on touching after resume. How to fully integrate start of things like sounds, touching, textures after resuming of applications at the same time? It looks like calling of music is fastest, next are textures and last is responsiveness on touching (sometimes few seconds latency). I would like to build applications fully protected on unwanted behaviours ;) I will appreciate any clues. I suppose that maybe some kind of my Achilles heel and time to drop armv6 devices but I would like to be wrong.
    ps My concerns refer ONLY to Gideros SDK 2012.08.* and next.
    Also I would like to say that performance of 2012.09.5 version is simply awesome even on small devices, thus it is very hard to put away armv6!
    Best Regards
  • atilimatilim Maintainer
    @fxone After your post, I've observed the same behavior on low end devices. For example, on HTC Wildfire games are working well but after unlocking touches doesn't respond about 1-2 seconds. But on Samsung S 2, touches start to respond immediately after unlocking.

    And I've installed Angry Birds to HTC Wildfire and test the same behavior on it. With Angry Birds, touches respond immediately after unlocking. Therefore there is solution to it and I'll look at it.

    Likes: fxone

    +1 -1 (+1 / -0 )Share on Facebook
  • @Atilim I've just checked the newest version of SDK 2012.09.7 and it doesn't solve the problem described above :((
  • atilimatilim Maintainer
    @fxone I couldn't make it on time :) Promise with the next release :)

    Likes: fxone

    +1 -1 (+1 / -0 )Share on Facebook
  • fxonefxone Member
    edited February 2013
    @Atilim, thank you so much for your work and kindness! Since version 2012.09.9 it works like a charm!
  • Is this the correct way to handle the app sent to background and resume?
    REAL programmers type copy con filename.exe
    ---------------------------------------
Sign In or Register to comment.