安卓:"应用水平和QUOT;暂停和恢复 [英] Android: "Application level" Pause and Resume

查看:218
本文介绍了安卓:"应用水平和QUOT;暂停和恢复的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

但我没有运气这么远。<​​/ P>

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

让我知道,如果你需要我粘贴一些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();
}
 

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();
}

这篇关于安卓:&QUOT;应用水平和QUOT;暂停和恢复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆