Skip to main content
Skip table of contents

Creating a New Android Studio Project

To create a new Android Studio project for Cantara Client
  1. Using Android Studio, create a new project for your mobile application.​



  2. Set the project and package names as in the screenshot below
  3. Select Kotlin as the language



  4. Configure the Gradle import settings according to Gradle Configuration (Android)
  5. Set up Android Studio preferences according to the Tools and Guidelines​.
  6. Refer to the procedure Entity Generation (Android) to generate project entity classes and the core data model.


To create the And​roid Application
  1. Create the main and launcher activity named HelloWorldRootActivity and make it a subclass of "RootActivity" from the CC6 library.
  2. Provide an empty implementation for the abstract base member function "showHomeActivity​()"
  3. Create an object file named HelloWorldBoxStoreFactory to set up ObjectBox as the local storage.​

    ​object HelloWorldBoxStoreFactory {

    ​​    const val BOX_STORE_ID: String = "cantara.helloWorld"

        private const val TAG: String = "HelloWorldBoxStoreFactory"

        private const val MAX_NUM_DB_READERS: Int = 500

        private const val MAX_DB_SIZE_KB: Long = (100 * 1024 * 1024)

        

        fun getBoxStore(context: CantaraApplication): BoxStore {

            var boxStore = context.boxStores[BOX_STORE_ID]

            

            if (boxStore == null) {

                try {

                    Log.i(TAG, "Generating helloWorld database box store")

                    boxStore = MyObjectBox.builder().androidContext(context).name(BOX_STORE_ID).

                                   maxSizeInKByte( MAX_DB_SIZE_KB ).maxReaders(MAX_NUM_DB_READERS).build()

                    context.boxStores[BOX_STORE_ID] = boxStore!!
                } catch (exc: Exception) {

                    Log.e(TAG, "Unable to create helloWorld database box store", exc)

                    throw RuntimeException(exc)

                }

            }

            return boxStore

        }

    }​



  4. Create the application class and make it a subclass of "CantaraApplication" from the CC6 library
  5. Add the following implementation to the application class:

    class HelloWorldApplication : CantaraApplication() {

        override fun deleteBoxStores() {

            HelloWorldBoxStoreFactory.getBoxStore(this) boxStores.map {

                it.value.removeAllObjects()

            }

        }

    }



  6. Create your Hello world activity named HelloWorldActivity.
  7. In the HelloWorldRootActivity you created earlier, start up the HelloWorldActivity in the member base function "showHomeActivity".

    override fun showHomeActivity() {

        val homeIntent = Intent(this, HelloWorldActivity::class.java)

        startActivityForResult(homeIntent, 0)

    }​



  8. Ensure that you have successfully completed the gradle configuration setup.
  9. Run the app and log in.


JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.