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)