Issue
I'm trying to learn how to develop Android and I'm currently following this tutorial on the activities lifecycle: https://developer.android.com/training/basics/activity-lifecycle/pausing.html
I created a very simple code to check the triggering of the onPause()
and onResume()
functions, e.g. for onPause()
I just wrote the following in one of my activities (and I did the same kind of stuff for the onResume()
function):
@Override
protected void onPause() {
super.onPause();
Toast.makeText(this, "ON PAUSE", Toast.LENGTH_LONG).show();
Log.i("STATUS_ON_PAUSE", "ON PAUSE");
}
When I start/stop the activity or when I switch from one activity to another I do see the corresponding Toasts and logs. But I don't see anything when I overlay a facebook-messenger conversation over my activity. No Toast when opening the conversation (I would have expected to see "ON PAUSE"), no Toast when giving the focus back to my application.
I tried to inspect the log-files on a broader level (my device) but I'm still not good enough to really understand what goes on there (way too much information). So, my question is: how come my activity is not paused/resumed when I give/remove focus to a chat-head? Thanks!
Solution
The simplest answer would be:
Messenger is adding a view to a Window instead of starting a new activity.
This is why Messenger needs SYSTEM_ALERT_WINDOW permission and you can see that when you see it's details: "draw over other apps" permission.
You can see THIS ARTICLE
- You won't get onPause or onResume when someone is drawing over your window.
- You will always get onPause and onStop when your activity is covered with other activity.
- You will always get onPause and no onStop when your activity is covered with a dialog styled activity (so that your activity is still visible in the background).
- You will not get onPause or onStop when your activity is covered by a DialogFragment - this may look exactly the same as a dialog styled activity but there is a difference in lifecycle and implementation.
Answered By - Mark
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.