>
> How to check if an Android application is running in the background 
> <http://www.google.com/url?q=http%3A%2F%2Fstackoverflow.com%2Fquestions%2F3667022%2Fchecking-if-an-android-application-is-running-in-the-background&sa=D&sntz=1&usg=AFQjCNGE1m5lcNZZSspL-DdyzKq6Q9SyXw>
>  or 
> in foreground ?
>
for exemple i have this code in my project :

public class Utilities extends Application{
    private static int stateCounter;

    public void onCreate()
    {
        super.onCreate();
        stateCounter = 0;
    }

    /**
     * @return true if application is on background
     * */
    public static boolean isApplicationOnBackground()
    {
        return stateCounter == 0;
    }

    //to be called on each Activity onStart()
    public static void activityStarted()
    {
        stateCounter++;
    }

    //to be called on each Activity onStop()
    public static void activityStopped()
    {
        stateCounter--;
    } 

}

but in ios is simple to detect the state :

let state: UIApplicationState = 
UIApplication.sharedApplication().applicationState // or use  let state =  
UIApplication.sharedApplication().applicationState
if state == .Background {
// background}else if state == .Active {
// foreground}

I m searching if android have another solution to do this test ? 

-- 
You received this message because you are subscribed to the Google Groups 
"Android Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to android-discuss+unsubscr...@googlegroups.com.
To post to this group, send email to android-discuss@googlegroups.com.
Visit this group at https://groups.google.com/group/android-discuss.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/android-discuss/c966137d-bd61-4b5b-85e6-c73c924a10fe%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to