2

I want to see any variable's value at runtime in Android Studio, I saw this post is-it-possible-to-watch-variables-at-runtime but in the answer, it is mentioned to set a breakpoint first and then see the value of the variable in the breakpoint.

But the thing is I want to add these breakpoints (variables whose values I want to see) at runtime, now is there any possible way I can do that.

Please help me, anyone.

Thanks

Sudhanshu Gaur
  • 7,486
  • 9
  • 47
  • 94
  • You can launch the program in a debug mode without any breakpoints at first, navigate through it and then at any point add a breakpoint while the program is running. Is that what you mean? – Suleyman May 07 '18 at 14:50
  • @LieForBananas exactly – Sudhanshu Gaur May 07 '18 at 14:53
  • 1
    But you can do it. For example, just now I launched a program without any breakpoints, then I decided to put a breakpoint in my `onClick` method, I put the breakpoint, then without relaunching the app I click on the button and it stops in a debug mode, after that if you are done you just press F9 and the execution continues, then you can put another one somewhere else and repeat. – Suleyman May 07 '18 at 14:56
  • @LieForBananas Thanks Yeah it's working but just one more question, after closing the app why debugger is getting removed I still want to debug and see the data inside the variables? – Sudhanshu Gaur May 07 '18 at 18:52
  • @LieForBananas I mean I still want to debug and see the data inside the variables after `opening my app again`? – Sudhanshu Gaur May 07 '18 at 19:00
  • I believe because the process associated with the debugger, which is your app is stopped or paused so it detaches. If it's not too much trouble than you can relaunch your app in a debug mode again, or another form of debugging is just put `Log` statements all over the place :) but I am sure you already know that. – Suleyman May 07 '18 at 19:06
  • @LieForBananas Yeah but at the runtime, I want to do everything so adding Logs will not work at runtime. – Sudhanshu Gaur May 07 '18 at 19:10
  • Yeah, I understand, but AFAIK the debugger will always detach if you close the app. – Suleyman May 07 '18 at 19:17
  • 1
    @LieForBananas Got the solution see the answer to this question https://stackoverflow.com/questions/17677506/android-studio-open-debug-mode-when-app-is-running Thanks anyways :) – Sudhanshu Gaur May 07 '18 at 19:20
  • Oh! Thanks for sharing :) Never knew that :) Good luck! – Suleyman May 07 '18 at 19:22

0 Answers0