安卓:"应用水平和QUOT;暂停和恢复水平和、QUOT

由网友(一个很哇塞的汉子)分享简介:我一直在试图让应用程序级别暂停和恢复类似活动的的onPause和onResume。我知道有没有API,它有这个功能。 我尝试按照这个帖子:的http://curioustechizen.blogspot.com/2012/12/android-application-level-pause-and.html但我没有运气...

我一直在试图让应用程序级别暂停和恢复类似活动的的onPause和onResume。我知道有没有API,它有这个功能。

我尝试按照这个帖子:的http://curioustechizen.blogspot.com/2012/12/android-application-level-pause-and.html

但我没有运气这么远。

有没有人能够做到这一点?你用什么模式?

让我知道,如果你需要我粘贴一些code到这个问题。 感谢您的帮助

解决方案

另一种解决问题的办法是将只保留ONSTART()和的onStop()的计数的轨迹,从每一个活动通话。例如:

首先,创建一个类来保存计数:

 公共类ActiveActivitiesTracker {
    私有静态诠释sActiveActivities = 0;

    公共静态无效activityStarted()
    {
        如果(sActiveActivities == 0)
        {
            // TODO:这里是presumably应用水平的简历
        }
        sActiveActivities ++;
    }

    公共静态无效activityStopped()
    {
        sActiveActivities--;
        如果(sActiveActivities == 0)
        {
            // TODO:这里是presumably应用水平暂停
        }
    }
}
 

然后,在每一个活动,只需调用activityStarted()和activityStopped()方法:

  @覆盖
公共无效的OnStart(){
    super.onStart();
    ActiveActivitiesTracker.activityStarted();
}

@覆盖
公共无效的onStop(){
    super.onStop();
    ActiveActivitiesTracker.activityStopped();
}
 
为什么iOS用户的Wi Fi使用率超过Android

I've been trying to get Application Level Pause and Resume similar to an activity's onPause and onResume. I know there's no API that has this functionality.

I try to follow this post: http://curioustechizen.blogspot.com/2012/12/android-application-level-pause-and.html

But I've had no luck so far.

Has anyone been able to achieve this? What paradigm did you use?

Let me know if you need me to paste some code into this question. Thanks for the help

解决方案

Another solution to the problem would be to just keep track of the count of onStart() and onStop() calls from every activity. Example:

First, create a class to hold the counts:

public class ActiveActivitiesTracker {
    private static int sActiveActivities = 0;

    public static void activityStarted()
    {
        if( sActiveActivities == 0 )
        {
            // TODO: Here is presumably "application level" resume
        }
        sActiveActivities++;
    }

    public static void activityStopped()
    {
        sActiveActivities--;
        if( sActiveActivities == 0 )
        {
            // TODO: Here is presumably "application level" pause
        }
    }
}

Then in every activity, simply call the activityStarted() and activityStopped() methods:

@Override
public void onStart() {
    super.onStart();
    ActiveActivitiesTracker.activityStarted();
}

@Override
public void onStop() {
    super.onStop();
    ActiveActivitiesTracker.activityStopped();
}

阅读全文

相关推荐

最新文章