2

So I'm looking at trying to understand Android's Activity lifecycle. One thing I don't quite see is when an activity could be paused without being stopped soon afterwards. The documentation I can find says this

This method [onPause] is called when the system is about to put the activity into the background or when the activity becomes partially obscured.

When exactly would an activity become partially obscured?

Earlz
  • 62,085
  • 98
  • 303
  • 499
  • when you have a dailogue over your activity.your activity will still be partially visible but it will be in paused state.as the user can click on the buttons if any in the dailog and can move to next activity or cancel the dailog to bring the partially visible activity again into view – khubaib Sep 24 '13 at 18:36
  • This would help you http://developer.android.com/training/basics/activity-lifecycle/pausing.html – S.A.Norton Stanley Sep 24 '13 at 18:37
  • When an activity goes out of focus, onPause() method is invoked by andoird system. Pause is the preparation stage before running another activity. This is the place where the existing state of the activity should be persisted. – Rohan Kadu Sep 24 '13 at 18:37
  • Check here: http://stackoverflow.com/questions/7240916/android-under-what-circumstances-would-a-dialog-appearing-cause-onpause-to-be – fasteque Sep 24 '13 at 18:37

3 Answers3

3

OnPause is called when an Activity is still in FG visible and running but is obscured such as when you start a Dialog the activity is still running in the FG and visible but its obscured by the Dialog, this is OnPause.

onStop is when we are completely in BG such as turned to new activity or so, it is still active and running but untouchable and not visible.

in a nutshell

Jony-Y
  • 1,579
  • 1
  • 13
  • 30
  • When you just start a dialog, on pause is not called. But when you start a Activity which is of style @style/Theme.AppCompat.Dialog or something, onPause is called and onStop is not. – Muhammad Riyaz Feb 28 '17 at 14:47
3

The statement means when your activity is no longer visible on the screen or is taken over by another activity.

For Example:

You have written a Calculator app. It has two activities, one is for calculation & taking user input and the other is for setting i-e; setting up type of calculator eg. Scientific, normal etc.

Consider at the moment calculator is being displayed on the screen, when you go to the settings of calculator app, user input activity is in backgroud (off the screen) and settings activity has taken over the screen (came to foreground), At this moment, user input activity is in Pause state.

Umer Farooq
  • 7,356
  • 7
  • 42
  • 67
  • "when your activity is no longer visible on the screen or is taken over by another activity." that seems to be when an activity is backgrounded though and onStop called shortly after onPause – Earlz Sep 24 '13 at 18:59
  • @Earlz According to docs it might or might not be called. It is upto the OS to decide when to call it. According to my experience, when the system is low on resources, OS calls onStop() for activities that are in onPause() state, this way they are a step closer to be destroyed when OS needs resources. Hope this helps. – Umer Farooq Sep 24 '13 at 19:06
2

When exactly would an activity become partially obscured?

This could happen say if a Dialog themed Activity comes in front. Activities with a transparent background would also cause this or Dialogs within the Activity. Basically when an Activity comes on top that isn't completely opaque and full screen.

codeMagic
  • 44,549
  • 13
  • 77
  • 93