how to check if a java application is running in background?

try

/**Flag to determine if the Activity is visible*/
    private static boolean activityVisible;
    private static boolean activityDestroy;

/**Is the application actually visible on the mobile screen*/
public static boolean isActivityVisible(){
    return activityVisible;
}

/**Is the application actually destroyed*/
public static boolean isActivityDestroy(){
    return activityDestroy;
}

/**Is the application actually destroyed*/
public static void activityDestroy(boolean isDestroy){
    activityDestroy = isDestroy;
}

/**Is the application actually in the background*/
public static boolean isActivityInBackground(){
    return !activityVisible;
}


/**Change the state of the Application to resume*/
public static void activityResumed() {
    activityVisible = true;
}

/**Change the state of the Application to paused*/
public static void activityPaused() {
    activityVisible = false;
}

and then for checking

    Application app = ((Application)getApplicationContext());
    boolean visible = app.isActivityVisible();

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top