Android Idle User Redirect to an other activity
<p>Hi want to redirect Idle user to my main Activity.</p>

<p>I follow exactly step by step what this guy are doing for that.</p>

<p><a href="http://stackoverflow.com/questions/4075180/application-idle-time">Application idle time</a></p>

<p>My problem is I don't even know how to redirect my user when the idle time is out <br />
Do I need to make an asynctask in my activity where I'll verify if the (idle > period)
<br />
Is there a way to have a kind of listener on the waiter thread class where tell my activity when the thread is stop. A kind of OnStop would be nice. <br /></p>

<p><br /></p>

<pre><code>public class ControlApplication extends Application
{
    private static final String TAG=ControlApplication.class.getName();
    private Waiter waiter;  //Thread which controls idle time

    // only lazy initializations here!
    @Override
    public void onCreate()
    {
        super.onCreate();
        Log.d(TAG, "Starting application"+this.toString());
        waiter=new Waiter(15*60*1000); //15 mins
        waiter.start();
    }

    public void touch()
    {
        waiter.touch();
    }
}
</code></pre>

<p>Class which will be parent for all of your activities</p>

<pre><code>public class ControlActivity extends Activity
{
    private static final String TAG=ControlActivity.class.getName();

    /**
     * Gets reference to global Application
     * @return must always be type of ControlApplication! See AndroidManifest.xml
     */
    public ControlApplication getApp()
    {
        return (ControlApplication )this.getApplication();
    }

    @Override
    public void onUserInteraction()
    {
        super.onUserInteraction();
        getApp().touch();
        Log.d(TAG, "User interaction to "+this.toString());
    }

}
</code></pre>

<p>And finally Thread itself</p>

<pre><code>public class Waiter extends Thread
{
    private static final String TAG=Waiter.class.getName();
    private long lastUsed;
    private long period;
    private boolean stop;

    public Waiter(long period)
    {
        this.period=period;
        stop=false;
    }

    public void run()
    {
        long idle=0;
        this.touch();
        do
        {
            idle=System.currentTimeMillis()-lastUsed;
            Log.d(TAG, "Application is idle for "+idle +" ms");
            try
            {
                Thread.sleep(5000); //check every 5 seconds
            }
            catch (InterruptedException e)
            {
                Log.d(TAG, "Waiter interrupted!");
            }
            if(idle &gt; period)
            {
                idle=0;
                //////////////////////
                //HERE IS SET THE STOP 
                stop = true;

            }
        }
        while(!stop);
        Log.d(TAG, "Finishing Waiter thread");
    }

    public synchronized void touch()
    {
        lastUsed=System.currentTimeMillis();
    }

    public synchronized void forceInterrupt()
    {
        this.interrupt();
    }

    //soft stopping of thread
    public synchronized void Stop()
    {
        stop=true;
    }

    public synchronized void setPeriod(long period)
    {
        this.period=period;
    }

}
</code></pre>
