Android Question Inline Java

Discussion in 'Android Questions' started by mlc, Mar 2, 2015.

  1. mlc

    mlc Active Member Licensed User

    Hello,
    Due to problems with RingtoneManagerWrapper.class and amazon, and to not have 2 Phone libraries (Phone2 without this class).
    I'm trying to replace PhoneWakeState.class, from Phone library, with this code:

    Code:
    Sub Process_Globals
        
    Private nm As JavaObject
    End Sub

    Sub Activity_Create(FirstTime As Boolean)

        
    If FirstTime Then
            nm.InitializeContext
        
    End If
        nm.RunMethod(
    "wake",Null)
    End Sub

    #If JAVA
    import android.view.WindowManager;
    import android.view.View;
    import android.view.Display;

    public void wake() {

        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        Display display = getWindowManager().getDefaultDisplay();
        View view = getWindow().getDecorView().findViewById(android.R.id.content);
        if (view != null){      
           view.setKeepScreenOn(true);
        }
    }

    #End If
    It works well, and the screen stays on.

    If I put the app in the background, the screen turns off and when I return to bring to the fore, the screen stays on. Perfect.

    But if I rotate the device then no longer useful, because when rotate, the screen turns off.

    This is the solution I found:
    I declare javaObject in Globals and initialize in activity_create

    Code:
    Sub Globals
        
    Dim nm As JavaObject
    End Sub

    Sub Activity_Create(FirstTime As Boolean)

        
    If FirstTime Then

        
    End If

        nm.InitializeContext
        nm.RunMethod(
    "wake",Null)

    End Sub
    Works perfectly, even when i rotate the device, but is correct?

    Thanks
     
  2. thedesolatesoul

    thedesolatesoul Expert Licensed User

    The documentation here is out of date: http://www.b4x.com/android/help/javaobject.html
    EDIT: Search for InitializeContext doesnt return any useful results: http://www.b4x.com/android/forum/pages/results/?query=InitializeContext&page=1&prefix=0
    EDIT2: Neither does a search for JavaObject return any useful results mentioning this method.

    If InitializeContext is taking the activity context then it is correct, you dont need to ensure its the first time. Also its not going to hurt doing it everytime the activity is created. I cant see why it needs to be wrapped in FirstTime.
     
    mlc likes this.
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