Java Question - order of initializing


Licensed User
Not sure how to explain this....I have never seen this before..

I am wrapping a project which has a demo-app where there is a class that extends the "" class. Let us call this class A.
The workflow of their demo-app is the following:
1) first thing is that class A runs with code in its onCreate method (there is no layout for this class)
2) class A then starts a service
3) finally the MainActivity is started and shows its layout.

I had a look at the manifest but I cannot find anything there which says that class A should be executed first.
I, therefore, guess that a class that extends the "" class will always run first (it will be the entry-point).

In my wrapper, I have included the class A but it will not execute in my B4A project.

Any idea how I could get class A running at the start of the library. Do I need to wrap it as well and create the usual initial method and perhaps run it in the Starter module of B4A?

Many thanks for any help I can get.


Licensed User
Extending Application is problematic in B4A.

Usually i do not use it; instead in do the intialization in my Wrapper.

Can you tell which project exactly you are wrapping?


Licensed User
I was wrong about the manifest. It actually has an entry in the manifest:

I set it and now the logs I put in class A show up. So it seems to work:
1 - We are in KCTApp in its onCreate method
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **

However, the service it should execute did not start but that might be another problem.

Anyway, here is the class A (

package com.kct.bluetooth_demo;

import android.content.ComponentName;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.util.Log;

import com.facebook.stetho.Stetho;
import com.kct.bluetooth.KCTBluetoothManager;
import com.kct.bluetooth_demo.db.DBOpenHelper;
import com.kct.bluetooth_demo.db.dao.DaoMaster;
import com.kct.bluetooth_demo.db.dao.DaoSession;

import org.greenrobot.greendao.database.Database;

* KCTApplication
public class KCTApp extends{

    private static KCTApp instance;
    private static KCTBluetoothService mKCTBluetoothService;

    private DaoSession mDaoSession;

    public static KCTApp getInstance() {
        Log.i("B4A","3 - We are in KCTApp");
        return instance;

    public static KCTBluetoothService getmBluetoothLeService() {
        return mKCTBluetoothService;

    public void onCreate() {
        instance = this;
        Log.i("B4A","1 - We are in KCTApp in its onCreate method


        DBOpenHelper helper = new DBOpenHelper(this, "bluetooth_demo");
        Database db = helper.getWritableDb();
        mDaoSession = new DaoMaster(db).newSession();



    public DaoSession getDaoSession() {
        return mDaoSession;

    public static void initBlueTooth() {
        Intent gattServiceIntent = new Intent(instance, KCTBluetoothService.class);
        instance.bindService(gattServiceIntent, mServiceConnection, BIND_AUTO_CREATE);

    public final static ServiceConnection mServiceConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName componentName, IBinder service) {
            try {mKCTBluetoothService = ((KCTBluetoothService.LocalBinder) service).getService();
                if (!mKCTBluetoothService.initialize()) {
            } catch (Exception e) {e.printStackTrace();}
        public void onServiceDisconnected(ComponentName componentName) {
            mKCTBluetoothService = null;}
Last edited: