Switching Views inside a TimerTask - Android
<p>I have the following code that responds to a button click, changes the view and then after 5 seconds switches the view back:</p>

<pre><code>public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);
    Button test = (Button)findViewById(R.id.browseLocation);
    test.setOnClickListener(testListener);
}
private TimerTask revert = new TimerTask(){
    @Override
    public void run() {
        setContentView(R.layout.menu);
    }
};
private OnClickListener testListener = new OnClickListener() {
    public void onClick(View v) {
        setContentView(R.layout.test);
        Timer tim = new Timer();
        tim.schedule(revert, 5000);
    }
};
</code></pre>

<p>However this code does not work. The run method of the timetask is hit but setContentView fails. I assume it has something to do with scope inside the timetask.
How can I achieve the desired result?</p>
