Bug? Landscape orientation issue cause by power button

capisx

Member
Licensed User
Longtime User
I had strange behavior with my app with landscape orientation, when i press the power button of my device the activity was paused then create and resume the activity but the device screen is still off, if i press the power button again the activity resume again.

---------
When power button pressed the log display: (Screen go off)
** Activity (main) Pause, UserClosed = false **
** Activity (main) Create, isFirst = false **
** Activity (main) Resume **

After power button pressed again the log display: (Screen back on)
** Activity (main) Resume **
----------

I've tried Erel's Asteroid gameview example that use landscape orientation and the issues above is also occurred too, tested with Lenovo A800 (ICS) and Samsung G-Tab 7" P1000 (Gingerbread).

Is there any solution for this issue? the samsung appstore reject one of my app that use landscape orientation for this reason :(
 

capisx

Member
Licensed User
Longtime User
Today i've tried to reproduce this bug on my nephew's Samsung G-Tab 2 7" (android 4.04) and it works fine too. It works fine too on my Lenovo A800 (4.0) after i disable the screen lock. It seems this bug was occurred on devices that use screen lock that can't be displayed on landscape mode, so when the power button was pressed it force the orientation to portrait (as far as i know, android smartphones screen lock is only in portrait mode, same as my G-Tab 7" Gingerbread).

Is there any solution for this Erel? can we capture the power button when it pressed (i've tried KeyCodes.KEYCODE_POWER but not working)?

PS: Can we know if activity got focus again after screen lock?
 
Last edited:

capisx

Member
Licensed User
Longtime User
Thanks Erel for the solution. I use your code below to workaround this issue:
B4X:
Sub IsScreenOn As Boolean
  Dim r As Reflector
  r.Target = r.GetContext
  r.Target = r.RunMethod2("getSystemService", "power", "java.lang.String")
  Return r.RunMethod("isScreenOn")
End Sub

Sub Activity_Resume
    If IsScreenOn=True Then
       'mycode here (start music, start timer, etc..)
    End If
End Sub

The code above is working. with this workaround, the code inside Activity_Resume will not launched if the screen is off. The problem is when the screen turn on the code inside Activity_Resume will be launched even though the activity still on background (screen lock on foreground).

I've tried to use Activity_WindowFocusChanged Event but it throw java.lang.NullPointerException when i press home button, why?
 

capisx

Member
Licensed User
Longtime User
Thanks again Erel for your fast response. I just found out that Activity_WindowFocusChanged Event error only occurs when compile in debug mode. I think i can use this event for handling landscape issue.
 

MMORETTI964

Member
Licensed User
Longtime User
Approximately same thing here (reproduced with home button). I write it if someone stuck into this error.
Seems there is something in Activity_WindowFocusChanged event (luckily this error occurs when compile in debug mode), on Samsung 10.1 in landscape mode (don't know if in portrait is the same as our application force landscape).
Step to reproduce:
1. Launch program
2. Press HOME button (on Samsung is a physical key)
3. Long press HOME button
4. Choice your program from recent programs.
5. Error (java null pointer) on screen and on B4

Immagine.png


Screenshot_2014-03-10-11-58-59.png



However if you compile in release mode this problem vanishes.

Maurizio
 

danijel

Active Member
Licensed User
Longtime User
I have same problem with landscape mode.
This is one step forward:
B4X:
Sub IsScreenOn As Boolean
  Dim r As Reflector
  r.Target = r.GetContext
  r.Target = r.RunMethod2("getSystemService", "power", "java.lang.String")
  Return r.RunMethod("isScreenOn")
End Sub

Sub Activity_Resume
  If IsScreenOn=True Then
  'mycode here (start music, start timer, etc..)
  End If
End Sub

But still I have to initialize all my views again (in landscape mode only)
And I must remember all current state for each one (visible, size, position...)
Is there way to avoid all that (prevent from remove)?
 
Top