android: Check if a View is bringed to front

Posted by user329692 on Stack Overflow See other posts from Stack Overflow or by user329692
Published on 2010-04-30T11:21:09Z Indexed on 2010/04/30 11:27 UTC
Read the original article Hit count: 280

Filed under:
|
|

Hi Guys! I made a custom component which simple extends a WebView

This component is used into activities that are loaded from a tabhost.

This component creates a timertask too.

I'd like to execute the task only if the activity that contains the component is visible.

Ex:

public class MyWebView extends WebView {
public MyWebView(Context context, AttributeSet as) {

    super(context,as);

    /** More code **/


        TimerTask ttask  = new TimerTask() {

            @Override
            public void run() {

                if (iamvisible)
                  doStuff();
            }
        };

        timer = new Timer();
        timer.schedule(ttask, refreshInterval * 1000, refreshInterval * 1000);

}
}

How can I set the iamvisible variable?

I tried overriding onWindowFocusChanged and onWindowVisibilityChanged but with no luck

Regards in advance

© Stack Overflow or respective owner

Related posts about android

Related posts about view