B4A Library Wrapper for Doki/Don't Kill My App

If you have worked on an app that has a service that needs to be running all the time, you must have gone through the delightful experience of different phones killing your background service in different ways, despite taking all the corrective measures. I get negative reviews routinely on Play Store almost exclusively due to this. I used to reply to every review explaining how they should disable battery optimization and a bunch of other stuff that varies from device to device.

Fortunately, a group of developers came together and created dontkillmyapp.com where they explain this situation, together with step by step device-specific guides on how to make sure an app doesn't get killed by the system. Now I usually email this link to my users and in some cases even link this website from within the app.

But now there is a better way to show this info in-app. A library called Doki is available which will automatically detect the phone manufacturer and display the corresponding guide. It is available as an activity or a msgbox.

https://github.com/DoubleDotLabs/doki

They also have a demo app which can be downloaded from here. Now, all we need is a wrapper so that we can display this within our B4A app.

1.png 3.png
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Step 1: download the dependencies: www.b4x.com/android/files/doki-0.0.1.zip
Download kotlin-stdlib: https://repo1.maven.org/maven2/org/jetbrains/kotlin/kotlin-stdlib/1.3.21/kotlin-stdlib-1.3.21.jar

Copy all files to the additional libraries folder.

Step 2:
Add to main module:
B4X:
    #AdditionalJar: jetified-doki-0.0.1.aar
   #AdditionalJar: jetified-core-3.0.0.aar
   #AdditionalJar: jetified-html-3.0.0.aar
   #AdditionalJar: jetified-image-okhttp-3.0.0.aar
   #AdditionalJar: doki-api-0.0.1.aar
   #AdditionalJar: rxandroid-2.1.1.aar
   #AdditionalJar: com.android.support:design
   #AdditionalJar: androidx.constraintlayout:constraintlayout
   #AdditionalJar: kotlin-stdlib-1.3.21
   #AdditionalJar: commonmark-0.12.1
   #AdditionalJar: retrofit-2.3.0
   #AdditionalJar: rxjava-2.2.6
   #AdditionalJar: adapter-rxjava2-2.3.0
   #AdditionalJar: gson-2.7
   #AdditionalJar: converter-gson-2.3.0
   #AdditionalJar: reactive-streams-1.0.2
   #AdditionalJar: androidx.appcompat:appcompat
You should also add a reference to OkHttpUtils2.

Step 3:
Declare the activity in the manifest editor:
B4X:
AddApplicationText(
 <activity
                android:name="dev.doubledot.doki.ui.DokiActivity"
                android:theme="@style/Theme.AppCompat.Light.NoActionBar" />
)
Step 4:
Start the activity:
B4X:
Sub Activity_Click
   Dim in As Intent
   in.Initialize("", "")
   in.SetComponent(Application.PackageName & "/" & "dev.doubledot.doki.ui.DokiActivity")
   StartActivity(in)
End Sub

As you can see, the library has many dependencies. This might cause problems in the long run.
 
Last edited:

Inman

Well-Known Member
Licensed User
Longtime User
Thanks Erel. I will try it out.
As you can see, the library has many dependencies. This might cause problems in the long run.

If it runs fine today, will it have any issue in the future as long as I don't try to add/update any of the dependencies?
 

Inman

Well-Known Member
Licensed User
Longtime User
I tried all the steps you mentioned, encountered a bunch of errors along the way due to my misconfiguration which I fixed. Now I can finally compile and when I click on the button to show the doki activity, I get the following error.
B4X:
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.app/dev.doubledot.doki.ui.DokiActivity}: java.lang.ClassNotFoundException: Didn't find class "dev.doubledot.doki.ui.DokiActivity" on path: DexPathList[[zip file "/data/app/com.apptuners.ringmaster-rMRsQnxg0mr_QukXdmyu0Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.app-rMRsQnxg0mr_QukXdmyu0Q==/lib/arm64, /system/lib64, /product/lib64]]
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3194)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)
    at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)
    at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)
    at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)
    at android.os.Handler.dispatchMessage(Handler.java:107)
    at android.os.Looper.loop(Looper.java:214)
    at android.app.ActivityThread.main(ActivityThread.java:7356)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
Caused by: java.lang.ClassNotFoundException: Didn't find class "dev.doubledot.doki.ui.DokiActivity" on path: DexPathList[[zip file "/data/app/com.app-rMRsQnxg0mr_QukXdmyu0Q==/base.apk"],nativeLibraryDirectories=[/data/app/com.app-rMRsQnxg0mr_QukXdmyu0Q==/lib/arm64, /system/lib64, /product/lib64]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:196)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
    at android.app.AppComponentFactory.instantiateActivity(AppComponentFactory.java:95)
    at android.app.Instrumentation.newActivity(Instrumentation.java:1250)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3182)
    ... 11 more
    Suppressed: java.lang.NoClassDefFoundError: Failed resolution of: Landroidx/appcompat/app/AppCompatActivity;
        at java.lang.VMClassLoader.findLoadedClass(Native Method)
        at java.lang.ClassLoader.findLoadedClass(ClassLoader.java:738)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:363)
        ... 15 more
    Caused by: java.lang.ClassNotFoundException: androidx.appcompat.app.AppCompatActivity
        ... 18 more
 

Inman

Well-Known Member
Licensed User
Longtime User
Thanks Erel. That worked. I had upgraded to B4A 9.50 from 9.0 only about an hour back to make sure I could get doki working. As a result many things changed including moving to androidx from old support libraries. I was using toolbar from appcompat in my app and so adding
#AdditionalJar: androidx.appcompat:appcompat fixed all the issues and got doki working as well.
 
Top