7

This is the scenario. I've just stopped a thread a have pressed the back key to return to the previous activity, only problem is I want to execute a method when this happens so I thought I could override a method using something like this:

  @Override protected void onResume() {
            super.onResume();
        }

But this seems to run when I start the activity. I want to have this functionality but when pressing the back key to return.

Sorry if it doesn't make sense, I'm not very knowledgeable of the terminology.

aelsheikh
  • 2,268
  • 5
  • 26
  • 41
  • There are several ways to handle this, depending on the context of where you are coming from. For example, Thread completion can be handled with a callback, intent calls can be handled using onNewIntent, etc. Posting the full code of how the new activity is called, and where it is closed will help us know what it is you need. – Phil Dec 07 '11 at 00:04
  • I'm pretty sure you'll find this question interesting: http://stackoverflow.com/questions/2441145/onpause-onresume-activity-issues – Michell Bak Dec 07 '11 at 00:04

1 Answers1

15

According to the official documentation, onResume() is exactly what you want - it always gets executed when the activity comes into foreground, either together with onCreate() and/or onStart() or alone, depending on the current process and activity states.

olex
  • 797
  • 5
  • 6
  • Correct, I took your word for it and squinted my eyes at the code. Turns out I was testing the function incorrectly. Thank you – aelsheikh Dec 07 '11 at 00:31
  • https://stackoverflow.com/a/58504433/5219642 for more detail you can check this – Amit Oct 25 '21 at 11:56