【问题标题】:Android app detect event when app brought to the foreground?当应用程序被带到前台时,Android应用程序检测事件?
【发布时间】:2016-08-30 23:33:58
【问题描述】:

现状及问题:

我的应用中有 10 多个活动,并且 AppController 类由 Application 类扩展。目前在 AppController 类中使用 onTrimMemory (TRIM_MEMORY_BACKGROUND) 将应用发送到后台时成功检测到 onbackground 事件。

现在我想在应用再次进入前台时检测事件。

有没有类似 onTrimMemory 的方法或事件?

提前致谢。

【问题讨论】:

    标签: android


    【解决方案1】:

    我们终于找到了解决办法!

    试试这个例子
    http://vardhan-justlikethat.blogspot.in/2014/02/android-solution-to-detect-when-android.html

    将应用程序与活动生命周期连接并检查 onTrimMemory 中的 isVisibleState。

    implements ActivityLifecycleCallbacks, ComponentCallbacks2 {  
    

    在 onTrimMemory 中

    @Override
           public void onTrimMemory(int level) {
                  if (stateOfLifeCycle.equals("Stop")) {
                         wasInBackground = true;
                  }
                  super.onTrimMemory(level);
           }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多