question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

finish()/onDestroy() is not being called for every activity.

See original GitHub issue

This might not be a bug - (but I didn’t see it documented anywhere) Is finish()/onDestroy() guaranteed to be called on every Activity started by ActivityTestRule, specifically in order? I’m seeing cases where onDestroy() is called, but the activity that’s returning isn’t being finished via isFinishing().

Some logs that show my findings: (@Before and @After are junit before/after methods)

D/OrderOfOp:    @Before        
D/OrderOfOp:    @After        
D/OrderOfOp:    onPause()        
D/OrderOfOp:    @Before        
D/OrderOfOp:    onDestroy()        
D/OrderOfOp:    onDestroy()    -->    isFinishing()
D/OrderOfOp:    @After        
D/OrderOfOp:    onPause()        
D/OrderOfOp:    @Before        
D/OrderOfOp:    @After        
D/OrderOfOp:    onPause()        
D/OrderOfOp:    @Before        
D/OrderOfOp:    onDestroy()        
D/OrderOfOp:    onDestroy()    -->    isFinishing()
D/OrderOfOp:    onPause()        
D/OrderOfOp:    onDestroy()        
D/OrderOfOp:    onDestroy()    -->    isFinishing()

(for reference, this is the onDestroy() method):

 @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("OrderOfOp", "onDestroy()");
        if (isFinishing()) {
            Log.d("OrderOfOp", "onDestroy() --> isFinishing()");
        }
    }

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
slinznercommented, May 31, 2016

This has been addressed in the next release!

1reaction
DreierFcommented, Mar 23, 2017

Is there any release date for 0.6? The last version as of now was 0.5 from 2016-02-22

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android: Will finish() ALWAYS call onDestroy()? - Stack Overflow
Third, finish() does not call onDestroy() . You can tell that by reading the source code. finish() usually triggers a call to onDestroy()...
Read more >
Android activity Lifecycle. An activity is a single, focused thing…
If the activity is finishing, onDestroy() is the final lifecycle callback the activity receives. If onDestroy() is called as the result of a...
Read more >
The activity lifecycle - Android Developers
An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial...
Read more >
4. The Activity Lifecycle: Being an Activity - Head First Android ...
The onDestroy() method is the final call you get before the activity is destroyed. There are a number of situations in which an...
Read more >
Activity Lifecycle | CodePath Android Cliffnotes
onDestroy(), Counterpart to onCreate(...) . This can be triggered because finish() was called on the activity or the system needed to free up...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found