Android Studio Koala

Hi, With Koala the Empty Activity defaults jetpack compose. I am making the presumption that the most similar “new project” to the xml version of Empty Activity is Empty Views Activity.
However the default MainActivity.kt is:

import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
setContentView(R.layout.activity_main)
ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets →
val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
insets
}
}
}

and I have replaced that with:

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity

class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}

The xml looks to be the same.

Also to get it to compile/run I had to chge the build.gadle.kts:
compileSdk = 35
targetSdk = 35

Am I correct in my assumptions?

Many thanks

1 Like

You are correct, we should use “Empty Views Activity” everytime we start a new project while following along with the book. I don’t know what “enableEdgeToEdge()” and it’s corresponding import statement does. I tried deleting them, didn’t notice any difference, ultimately I left them in. I left all the starter code in MainActivity.kt alone. I believe your replacement code will work for a while, however, notice at the beginning of each chapter in the book there will be a picture of how your project will look by the end of the chapter. Notice that these examples in the book have a navigation bar at the top whereas your project doesn’t. This will eventually become an issue as you make progress in the book. I would recommend leaving the default code of main activity as it is, and adding an

android:id="@+id/main"

tag to activity_main.xml to resolve the error thrown by “R.id.main” in:

    ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
        val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
        v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
        insets
    }

To get a navigation bar showing you will need the above code and you will need to edit res/values/themes.xml. In res/values/themes.xml change

style name=“Base.Theme.GeoQuiz” parent=“Theme.Material3.DayNight.NoActionBar”

to

<style name="Base.Theme.GeoQuiz" parent="Theme.MaterialComponents.DayNight.DarkActionBar">

Hi Phil
Thank you so much for answering this. Having the Forum linked to the book is a very good asset. Enjoying the book very much.
All the best from Barry Island in South Wales UK
Ric

Good advice. I will post any other differences I come across. Thank you for your reply