Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Check application screen visibility

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 99
    Comment on it

    Hey do you want to run some code on basis of screen visibility in your app..you can create an Application level class and can set every screen visibility in onResume or in onPaused like this :

    public class ThisApplication extends Application {
    private static boolean myActivityVisible;
    public static boolean ismyActivityVisible() {
        return myActivityVisible;
    }  
    public static voidmyActivityResumed() {
        myActivityVisible = true;
    }
    public static void myActivityPaused() {
        myActivityVisible = false;
    }
    

    Now you can set visibility like this :

        @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        MyApplication.mainActivityPaused();
    }
    
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        MyApplication.mainActivityResumed();
    }
    

    and can check here :

            if(MyApplication.isMainActivityVisible())
        {
           //Means activity not in background so dont start service or broadcasting
        }
        else
        {
          //Means activity is in background so start service here..
         } 
    

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: