Android Question dontkillmyapp.com: possible solution translation to B4A

koffie

Member
Licensed User
Longtime 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).

B4X:
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.
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
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.
 
Upvote 0

koffie

Member
Licensed User
Longtime 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
 
Upvote 0
Top