---
title: "How to check whether an android application running in background"  
description: "How to check whether an android application running in background"  
author: "Anonymous User"  
published: 2015-10-12  
updated: 2015-10-12  
canonical: https://www.mindstick.com/forum/33508/how-to-check-whether-an-android-application-running-in-background  
category: "android"  
tags: ["android", "android libraries"]  
reading_time: 2 minutes  

---

# How to check whether an android application running in background

How to [detect](https://www.mindstick.com/forum/1906/detect-when-cd-drive-was-closed) [weather](https://yourviews.mindstick.com/view/139/changing-weather-is-this-only-tip-of-an-ice-berg) an [android](https://www.mindstick.com/articles/13046/10-reasons-why-i-prefer-android-vs-iphone-ios) [application is running](https://answers.mindstick.com/qa/33369/how-will-you-find-if-your-application-is-running-on-low-memory-or-out-of-memory) in [background](https://www.mindstick.com/articles/65/how-to-change-background-color-of-tab-control-in-c-sharp) or not ,by background, I [mean](https://yourviews.mindstick.com/view/80768/what-does-real-minority-mean) none of the application's [activities](https://www.mindstick.com/interview/2589/describe-android-activities-in-brief) are currently visible to the [user](https://www.mindstick.com/articles/13001/multi-statement-table-valued-user-defined-function-in-sql-server)?

## Replies

### Reply by Anonymous User

Track visibility of your [application](https://www.mindstick.com/articles/12824/calculator-application-in-android) by yourself using Activity.onPause, Activity.onResume methods. Store "visibility" status in some other class. Good choices are your own implementation of the Application or a Service\
**Example**Implement custom Application class (note the isActivityVisible() static method):\

```
public class MyApplication extends Application {  public static boolean isActivityVisible() {    return activityVisible;  }    public static void activityResumed() {    activityVisible = true;  }  public static void activityPaused() {    activityVisible = false;  }  private static boolean activityVisible;}
```

Register your application class in AndroidManifest.xml:

```
<application    android:name="your.app.package.MyApplication"    android:icon="@drawable/icon"    android:label="@string/app_name" >
```

Add onPause and onResume to every Activity in the project (you may create a common ancestor for your Activities if you'd like to, but if your activity is already extended from MapActivity/ListActivity etc. you still need to write the following by hand):

```
@Overrideprotected void onResume() {  super.onResume();  MyApplication.activityResumed();}@Overrideprotected void onPause() {  super.onPause();  MyApplication.activityPaused();}
```

Also,ActivityLifecycleCallbacks were added in API level 14 (Android 4.0). You can use them to track whether an activity of your application is currently visible to the user. Check Cornstalks' answer below for the details.


---

Original Source: https://www.mindstick.com/forum/33508/how-to-check-whether-an-android-application-running-in-background

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
