Ryan Burnham
Ryan Burnham

Reputation: 593

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

Upvotes: 40

Views: 5551

Answers (3)

Kai
Kai

Reputation: 1769

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.

Upvotes: 9

Gharjyot Singh
Gharjyot Singh

Reputation: 59

You can try a better android device which could withstand the load of debugging without crashing the application. It has happened with me, now I am using Nexus 5x which is best for development purpose.

Upvotes: -2

chefish
chefish

Reputation: 595

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

Upvotes: 7

Related Questions