Android Question Immersive mode causes a crash in debug mode

Discussion in 'Android Questions' started by LucaMs, Jul 7, 2018.

  1. LucaMs

    LucaMs Expert Licensed User

    I "set" immersive mode for the Main; from here I start another Activity and Activity_WindowFocusChanged causes a crash if I start the app in debug mode (see the test project attached).

    Copying updated assets files (1)
    *** Service (starter) Create ***
    ** Service (starter) Start **
    ** Activity (main) Create, isFirst = true **
    ** Activity (main) Resume **
    ** Activity (main) Pause, UserClosed = false **
    Error occurred on line: 44 (Main)
    java.lang.NullPointerException
    at b4a.example.main._activity_windowfocuschanged(main.java:427)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at b4a.example.main.onWindowFocusChanged(main.java:185)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2678)
    at android.view.View.dispatchWindowFocusChanged(View.java:8018)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3289)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
    at dalvik.system.NativeStart.main(Native Method)

    Tested only on an Android 4.4.2.
     

    Attached Files:

    Last edited: Jul 7, 2018
  2. LucaMs

    LucaMs Expert Licensed User

    In the test project attached to the first post, it seems you can solve by changing Sleep(300) to Sleep(100):
    Code:
    Sub Activity_WindowFocusChanged(HasFocus As Boolean)
        
    If HasFocus Then
            
    Try
                
    Dim jo As JavaObject = Activity
                Sleep(
    100)
                jo.RunMethod(
    "setSystemUiVisibility"Array As Object(5894)) '3846 - non-sticky
            Catch
                
    Log(LastException)
            
    End Try
        
    End If
    End Sub
    but in other projects this change does not solve.
     
  3. Filippo

    Filippo Expert Licensed User

    Did you read that from Erel?
    I tried it with the tip of Erel and it works. :)
     
    LucaMs likes this.
  4. LucaMs

    LucaMs Expert Licensed User

    I had read that quickly and I had assumed that the code had been "fixed".

    My project crashes even commenting that line.
     
  5. LucaMs

    LucaMs Expert Licensed User

    ... but commenting that line and setting again Sleep to 300 it's ok :)
     
  6. LucaMs

    LucaMs Expert Licensed User

    No, it crashes... randomly :confused:
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Can you post the logs after you commented the relevant line?
     
  8. LucaMs

    LucaMs Expert Licensed User

    Sometimes the error happens when I write nothing in the Catch part; so I write a Sleep there but... sometimes Sleep(100) is not enough, I have to increase the time, sometimes it is the opposite, I have to decrease this value.

    Going by trial:
    sometimes it can be solved by "cleaning" the project (CTRL+P), other times stopping the project using the device settings.


    ** Activity (main) Pause, UserClosed = false **
    Error occurred on line: 393 (Main)
    java.lang.NullPointerException
    at mbnt.MyProjName.it.main._activity_windowfocuschanged(main.java:695)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:735)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:357)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:260)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at mbnt.MyProjName.it.main.onWindowFocusChanged(main.java:185)
    at com.android.internal.policy.impl.PhoneWindow$DecorView.onWindowFocusChanged(PhoneWindow.java:2678)
    at android.view.View.dispatchWindowFocusChanged(View.java:8018)
    at android.view.ViewGroup.dispatchWindowFocusChanged(ViewGroup.java:968)
    at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3289)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:149)
    at android.app.ActivityThread.main(ActivityThread.java:5257)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:610)
    at dalvik.system.NativeStart.main(Native Method)
     
  9. LucaMs

    LucaMs Expert Licensed User

    To solve THIS TIME (previous post):

    tried both, cleaning and stopping the project, without success.

    I added sleep (100) and this solved (then I received the same error in another Activity, resolved in the same way).
     
  10. LucaMs

    LucaMs Expert Licensed User

    Well, MAYBE I found something "useful" (for Erel :)).

    Catch block empty. Start B4A, open the project, run and you get the error.
    Change the Sleep command (it does not matter how many ms) inside the Activity_FocusChanged event routine and you no more get the error (in the same "b4a session").

    Save the project changed, open and start it again... and again you get the error.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice