Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to step back a line of code with Android Studio debugger

I am new to the debugger. When I step over a line of code, I was wondering how to step back. Now I'm realizing that the code can't be executed backwards? Do I have to restart the activity in debug if I want to step back to old lines?

Also, if you don't mind, what is the force-step-into command?

like image 331
the_prole Avatar asked Apr 25 '17 19:04

the_prole


4 Answers

Don't think that is possible. Android works like all other debuggers, which are more or less waterfalls over the code. You can't really step backwards, but thats where breakpoints come in. Place a break point before the line you wanted to step backward on and rerun your app, it'll keep going until it hits that line.

To explain Force-Step-Into I'm going to explain Step-Into/Over first. Step-Over sees the line you want, and steps over it, stopping at the line in the same file after the function call was made. Step Into on the other hand steps into the function call and stops on the first line of that function call, could be in a new file or a new location. In Android, there are a lot of functions that are considered "Black Boxes" where you don't really care what they do since they most probably don't affect the code (Like the Log.d function). Force Step Into allows you to step into those if you'd want to.

Source: https://www.quora.com/How-would-you-explain-in-one-line-about-Step-over-Step-into-Force-Step-into-and-Step-out-of-Android-studio

like image 161
OmegaNalphA Avatar answered Nov 15 '22 08:11

OmegaNalphA


Notice that you can set conditional breakpoint, i.e. breakpoint will stop execution only if x == 57 (so you don't have to skip manually all 56 breaks). Very useful. Just set breakpoint, click with right button on it and set your condition.

like image 27
MilanG Avatar answered Nov 15 '22 08:11

MilanG


May be Frames can help to check method() calling stack in debugger window

Frames in debugger window

like image 3
dastan Avatar answered Nov 15 '22 09:11

dastan


YES, you can!

According to the Android Dev Summit in 2019, now you can step back while debugging with Android Studio!

Check out the live demonstration.

All you need to do is to press the Drop Frame button in your debug view, and then Resume Program. Then you will automatically get back to the last break-point.

enter image description here

Note: the device should run at least Android 10.

like image 2
genericUser Avatar answered Nov 15 '22 09:11

genericUser