现状和问题:
我有超过10个活动在我的应用程序和AppController类扩展的应用程序类。目前,在使用onTrimMemory (TRIM_MEMORY_BACKGROUND)在AppController类中向后台发送应用程序时,成功地检测到了背景事件。
现在,我想检测事件,当应用程序再次出现在前台。
有像onTrimMemory这样的方法或事件吗?
提前谢谢。
发布于 2016-05-05 14:35:04
我们终于找到了解决办法!
试试这个例子
http://vardhan-justlikethat.blogspot.in/2014/02/android-solution-to-detect-when-android.html
将应用程序与活动生命周期连接起来,并在isVisibleState中检查onTrimMemory。
即
implements ActivityLifecycleCallbacks, ComponentCallbacks2 { 在onTrimMemory中
@Override
public void onTrimMemory(int level) {
if (stateOfLifeCycle.equals("Stop")) {
wasInBackground = true;
}
super.onTrimMemory(level);
}https://stackoverflow.com/questions/37046202
复制相似问题