2

When an activity goes into paused state, which can happen when it is partially covered by another activity, what exactly goes into the paused state? More precisely:

  1. Does it pauses Looper from processing incoming tasks or msgs, but it still allows job to be submitted in the Looper msg queue?
  2. If an activity has a messenger, which receives msgs from, suppose a service, is the messenger queue is also paused for processing the task, and but it can still receive msgs? Almost like above case no. 1.
  3. If case 1 or 2 or (1 and 2) are valid then I don't need to take care of UI task buffer for paused state (as suggested in the post How to handle Handler messages when activity/fragment is paused), because once the Activity resumes it will start processing messaging queue and nothing will be lost. Am I right in this assumption?

I feel this is how it should have been implemented, but not sure if this is the case.

Community
  • 1
  • 1
Vivek
  • 25
  • 3

2 Answers2

3

Generally, an Activity is paused means its UI elements are not frontmost. The UI thread is still working. That means the Looper can still process messages. The messenger you mention can still work.

Although the UI elements may not be visible, you can still change their states in background. For example, change a TextView's text. You can see such changes once the Activity is resumed again.

shhp
  • 3,653
  • 2
  • 18
  • 23
  • So it is like, all the tasks are still performed by the Looper/Messenger even after the Activity went in paused state, but just the rendering is conditionally skipped (kind of paused), rest is all same. – Vivek Aug 05 '16 at 08:44
  • Then what happens when an Activity is stopped. What does stopping mean? Does in this case, Looper is stopped(/blocked for task submission)? Because after onStop(), when an Activity comes at front it goes through onRestart() -> onStart() ->onResume(), in this case it must be doing more than what it does in when resuming from Paused state. – Vivek Aug 05 '16 at 08:50
  • In my opinion, the state of stop is more related with UI, e.g. UI elements are not visible. The operating system stop an `Activity` so that the user can interact with other `Activities`. – shhp Aug 05 '16 at 09:31
  • I think, you are right about paused state (though I have to experiment), but for the stop state it make more sense to completely stop the process (at least of Looper job queue processing), because it does not make sense to use system resources for an Activity which is not visible. This is the reason, if that is what we want, Android has Service. – Vivek Aug 05 '16 at 10:54
  • I think in stopped state it will not process anything from the queue. It is better let the Service know about the state of the Activity and buffer everything in the Service itself. Once the activity is relaunched it should consult the service and do the rendering. I am still looking for more precise answer to this :). – Vivek Aug 05 '16 at 10:54
  • Even the `Activity` is stopped, the Looper is still working. You can try to post a delayed (e.g. 10s) `Runnable` in `onPause` which logs a message. – shhp Aug 05 '16 at 11:34
0

in Simple Words .... An activity is in a paused state when the activity is visible but not in focus. It is in Background.

Nitin Thakor
  • 535
  • 3
  • 15
  • Thanks for the reply, but I am looking more than this. We know it is in paused state, but my question is what paused state means, from a process running point of view? – Vivek Aug 05 '16 at 07:33