Skip to content

Commit

Permalink
feat(Android): 支持应用前后台判断
Browse files Browse the repository at this point in the history
  • Loading branch information
bbssyyuui committed Mar 15, 2023
1 parent 7143a02 commit 79f66aa
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class ActivityStackManager implements Application.ActivityLifecycleCallbacks {

private Stack<Activity> stack;
private volatile int resumeCounter = 0;

private static class Instance {
public static ActivityStackManager INSTANCE = new ActivityStackManager();
Expand Down Expand Up @@ -177,6 +178,13 @@ public void finishAllActivity() {
}
}

/**
* 判断应用是否在后台
*/
public boolean isBackgroundRunning() {
return resumeCounter == 0;
}

private String getPageIdFromActivity(Activity activity) {
if (activity == null) {
return null;
Expand Down Expand Up @@ -221,12 +229,12 @@ public void onActivityStarted(Activity activity) {

@Override
public void onActivityResumed(Activity activity) {

resumeCounter++;
}

@Override
public void onActivityPaused(Activity activity) {

resumeCounter--;
}

@Override
Expand Down

0 comments on commit 79f66aa

Please sign in to comment.