简体   繁体   English

Android:为什么活动在onPause?

[英]Android :Why the Activity is in onPause?

I must to know if my Activity is displayed or not. 我必须知道我的活动是否显示。 I would to use the method onPause and onResume but I want to know also why the activity is in onPause.... There are 3 cases : 我想使用onPause和onResume方法,但我想知道为什么活动在onPause ....有3种情况:

  1. Activity in onPause because the display turn off onPause中的活动,因为显示关闭
  2. Activity in onPause because the user have clicked the home button onPause中的活动,因为用户已单击主页按钮
  3. Activity in onPause because the user have clicked the home button and screen off onPause中的活动,因为用户已单击主页按钮并关闭屏幕

How can I do ? 我能怎么做 ? Thanks 谢谢

EDIT : I resolved with this code : 编辑:我解决了这个代码:

ActivityManager activityManager = (ActivityManager)getContext().                .getSystemService(Context.ACTIVITY_SERVICE);
List<RunningTaskInfo> runningTasks = activityManager.getRunningTasks(Integer.MAX_VALUE));

* 1. * Activity in onPause because the display turn off and if any call appear : onPause() called * 1. * onPause中的活动,因为显示屏关闭,如果出现任何调用: onPause()调用

* 2. *Activity in onPause because the user have clicked the home button : onUserLeaveHint() called before onPause() if user press home button * 2. * onPause中的活动,因为用户点击了主页按钮: onUserLeaveHint()onPause()之前调用,如果用户按下主页按钮

* 3. *When user press Back key : onUserInteraction() called before onPause() * 3. *当用户按下返回键时:在onPause()之前调用onUserInteraction() ()

When You leave from one Activity to other Activity the activity from where you are leaving that activity onPause get called. 当您从一个Activity离开到其他Activity时,您将离开该活动的活动onPause被调用。 If you want to experiment create all the function Inside the onStart call the other activity onPause of the First activity get called. 如果你想实验创建所有函数在onStart调用内,调用第一个活动的其他活动onPause。

For more Information please go through by below link: 欲了解更多信息,请通过以下链接:

http://developer.android.com/guide/topics/fundamentals/activities.html http://developer.android.com/guide/topics/fundamentals/activities.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM