https://kotlinlang.org logo
#android
Title
# android
f

febs

11/13/2018, 9:10 PM
Trying to debug my first trivial app made with Kotlin with Android Studio. No matter if I tap "step over", I still end up in the Java source code of the Android framework. Is that normal? Apologies if this is not strictly Kotlin related.
m

MrNiamh

11/13/2018, 9:11 PM
Your code is in Kotlin, but Android is still written in Java
f

febs

11/13/2018, 9:12 PM
Thanks. Yep, I am aware of that 🙂 I am just wondering though, stepping over shouldn't just allow me to step into the lines of my Kotlin code rather than digging into the framework?
a

Alan Evans

11/13/2018, 9:12 PM
which icon are you pressing exactly?
definitely this one?
f

febs

11/13/2018, 9:22 PM
yup
I also added this just to be sure, but that was in vain.
I tried again just to be sure, using the "f8" shortcut for "step over", and no way, I ended up in Activity.java. Do this happen only to me? 🤔
e

Egor Trutenko

11/14/2018, 10:33 AM
Just a reminder, that if you come to an end of so-called "Android lifecycle callback" function, e.g.
onCreate
,
onResume
or
onDestroy
, you'll anyway end up in Activity source code, because callbacks that you write are called by the Android System through its own code
f

febs

11/14/2018, 11:47 AM
THAT was it! Thanks! ❤️ Although I still don't get why 🤔. Shouldn't the debugger allow me to stay in my very own code anyways? 🤔🤔🤔
e

Egor Trutenko

11/14/2018, 11:55 AM
No? Basically, when the system calls your functions, it goes like
System Events Looper
->
Activity.*callback name*
->
*your callback*
So when the execution of your callback is over, it returns to what's on top of execution stack, that is, methods in
Activity.java
❤️ 1
f

febs

11/14/2018, 11:59 AM
Thanks, it is more clear now. I moved the breakpoint elsewhere in the code and I get the same behavior though
e

Egor Trutenko

11/14/2018, 12:08 PM
Because any Android application (and UI applications as well, for that matter) are "reactive". This means, that by writing your code you define how you react on events, coming from the system, nothing more. That's why execution of any code you are writing will eventually end up in system code - because it's system that always triggers execution. So, if you want to debug your code, you need to place breakpoints in any function, that's being called by the system and which after completion returns into system. Examples of such functions are aforementioned callbacks:
onCreate
,
onResume
,
onDestroy
etc., basically everything that you don't call yourself. I assume you're trying to debug through lifecycle functions in order they are called?
onCreate
->
onStart
->
onResume
etc., right? Think of it like they are not executed one right after another - it's system that handles device's resources, so all of these methods are called asynchronously, at any time that you can't predict. That's why you have to place breakpoints in all of them and let execution go as a function finishes and returns execution back to the system
f

febs

11/15/2018, 9:51 AM
Thank you so much for the deep answer!
I managed to achieve what I wanted! I had to exclude from stepping com.android.* and android.* That finally worked.