1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

Android Question dontkillmyapp.com: possible solution translation to B4A

Discussion in 'Android Questions' started by koffie, Aug 1, 2019.

  1. koffie

    koffie Member Licensed User

    Hello,
    Long story short: I got really frustrated my app got killed, no matter what. Tried lots of solutions on this board.
    Found dontkillmyapp.com and for my very old Huawei there was a "possible" solution spelled out with the following code:
    (https://dontkillmyapp.com/huawei).

    Code:
    String tag = "com.my_app:LOCK";

    if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M && Build.MANUFACTURER.equals("Huawei")) { tag = "LocationManagerService"}

    PowerManager.WakeLock wakeLock = ((PowerManager) getSystemService(Context.POWER_SERVICE)).newWakeLock(1, tag); wakeLock.acquire();
    The key issue is using the { tag = "LocationManagerService"; } in/for/with the (partial) wakelock. This (supposedly) stops triggering the Huawei to kill the app.

    Can somebody guide me in how to translate the above code in the B4A syntax, if possible ?

    Regards,

    PS: Major mobile brands are mentioned on the site with possible solutions to killing processes by the OS.
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    Code:
    Dim wake As PhoneWakeState 'ignore. this will add the required permission
    Dim ctxt As JavaObject
    ctxt.InitializeContext
    Dim WakeLock As JavaObject
    WakeLock = ctxt.RunMethodJO(
    "getSystemService"Array("power")).RunMethod("newWakeLock"Array(1"LocationManagerService"))
    WakeLock.RunMethod(
    "acquire"Null)
    The other stuff should be accessible with the Phone library.
     
    José J. Aguilar and DonManfred like this.
  3. koffie

    koffie Member Licensed User

    Thanks,

    Would be impossible for me to figure this JavaObject stuff out.

    Will get back in here to post results for other Huawei owners
     
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