Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Application closing when debugging code block finishes

I've just setup a dev environment for an existing android app. Everything appears to be setup correctly, I can build the app, add breakpoints and debug the app. But i've noticed some odd behavior and i can't seem to find anything related to the problem.

  1. When i start the emulator or run the app on a device i can walk though the app and everything works as expected
  2. When i run the debugger and ad a breakpoint the breakpoint is hit fine and i can step through the code.
  3. When i step out of the last code block that had the initial break point using F7(step-into) or F8(step-over) the application closes and the debugger stops. There are no errors in android monitor > logcat.
  4. If i do the same set of step but instead use F9 to resume the program the application does not close and everything runs normally.

It seems like this might have something to do with the activity thread finishing and probably a Android Studio debug option? I'm not really sure though, i'm still new to android development.

Why would the debugger be stopping like this? Is there a way to ensure you run to the next breakpoint?

Edit

I can also reproduce this with a new android project my adding a breakpoint into the OnCreate method and stepping through to he end like this

    @Override protected void onCreate(Bundle savedInstanceState) {     super.onCreate(savedInstanceState);    <------- Breakpoint added here     setContentView(R.layout.activity_main);          ......          NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);     navigationView.setNavigationItemSelectedListener(this); }    <------- Application terminates after this line 
like image 530
Ryan Burnham Avatar asked Jun 10 '16 06:06

Ryan Burnham


People also ask

How do I run Android in debug mode?

Press Ctrl + Alt + F5 (or Shift + F9 ) to launch the app in debug mode. Choose Run -> Attach to process and select the signature of an app to enable the debug mode, which is already installed via adb.


2 Answers

It seems like this is a bug See issue tracker link

Using continue instead of step over at the end of methods should resolve the issue as mentioned above. Although you might need to add extra logging and put break points anywhere you expect the code to go after that method to make debugging later methods easier.

like image 177
Kai Avatar answered Sep 24 '22 14:09

Kai


Dont use step-over when you reach the end of funciton,just use "resume program",then it will goto the next breakpoint.

like image 35
chefish Avatar answered Sep 23 '22 14:09

chefish