I'm making an application contains about 20 activities and I want to start a count up timer when the activity 1 starts and finish counting on the last activity. I've found a way to make a subclass and call the timer in 1 activity But I didn't know how to pass the value of the timer from activity 1 to activity 2 and from 2 to 3 . this is my code
subclass
package com.mytimer;
import java.lang.ref.WeakReference;
import java.util.TimerTask;
import android.os.Handler;
import android.widget.TextView;
public class IncrementTask extends TimerTask {
WeakReference<TextView> mRef;
int counter = 0;
Handler handler = new Handler();
public IncrementTask(TextView text) {
mRef = new WeakReference<TextView>(text);
}
public void run() {
handler.post(new Runnable() {
public void run() {
mRef.get().setText("counter " + counter);
counter++;
}
});
}
}
in my activity 1
TextView mTextView = (TextView)findViewById(R.id.text);
Timer timer = new Timer();
IncrementTask task = new IncrementTask(mTextView);
timer.scheduleAtFixedRate(task, 0, 1000);
Button btn = (Button)findViewById(R.id.button1);
btn.setOnClickListener(new OnClickListener(){
@Override
public void onClick(View v) {
Intent i = new Intent (MainActivity.this, Page2.class);
startActivity(i);
}
});
I want to know how to pass the value of the timer to the next activity not start the timer from 0 any help please