android: how to append text to TextView in another activity every 2 seconds
<p>I have two activities, one is main and I have another activity called Test as well</p>

<p>in the main activity i have a button when I click on this button I go to the Test activity</p>

<p>in the Test activity I want the application to automatically append some text to the textview that it has every 10 seconds</p>

<p>this text can be for example "test"
so every 10 seconds "test" will be added
but, when I leave the activity and go to the main activity, this process will continue happening
so if for example I spend 20 seconds on the main activity and then return to the Test activity, I will see two more "test" strings in the textview..</p>

<p>I tried doing this with timertask and had no success at all</p>

<p>this is the Test activity's code, in the main activity I just have the button that shows me the other activity</p>

<pre><code>public class test2 extends Activity {
    /** Called when the activity is first created. */

    private TimerTask task;
    private Handler handler;
    private TextView tv;
    private Timer t;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.text1);

        t = new Timer();
        task = new TimerTask() {
            public void run() {
                handler.post(new Runnable() {
                    public void run() {
                        TextView tv = (TextView) findViewById(R.id.tv1);
                        tv.append("test");

                    }
                });

            }
        };
        t.schedule(task, 2000);
    }
}
</code></pre>

<p>when I click in the button of the main activity in order to go to the Test activity I get the following error:</p>

<pre><code>                FATAL EXCEPTION: Timer-0
                java.lang.NullPointerException
</code></pre>

<p>thanks in advance</p>
