这里我有3个活动:A,B和C.来自活动A当我点击一个按钮时,它将进入活动B.当活动B加载倒计时时,计时器将启动。再次,当我单击活动B中的按钮时,它将转到活动C.这里我需要帮助。
public class MainActivity extends Activity {
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.actone);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Act_Two.class);
startActivity(intent);
}
});
}
}
public class Act_Two extends Activity{
Button button;
public TextView textView1;
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.act_two);
textView1=(TextView) findViewById(R.id.textView1);
MyCount counter = new MyCount(61000,1000);
counter.start();
addListenerOnButton();
}
public void addListenerOnButton() {
final Context context = this;
button = (Button) findViewById(R.id.acttwo);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Intent intent = new Intent(context, Act_Three.class);
startActivity(intent);
}
});
}
public class MyCount extends CountDownTimer{
public MyCount(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
}
//iFallApp app1 = new iFallApp();
@Override
public void onFinish() {
// TODO Auto-generated method stub
setContentView(R.layout.activity_main);
//textView1.setText("done");
}
@Override
public void onTick(long millisUntilFinished) {
// TODO Auto-generated method stub
textView1.setText(Long.toString(millisUntilFinished/1000));
}
}
}
答案 0 :(得分:0)
您需要的最好的事情是使用线程。看看以下链接。如果您遇到问题,可以进一步询问
http://developer.android.com/guide/components/processes-and-threads.html
答案 1 :(得分:0)
您应该在Activty B中保存CountDownTimer
的值,并在Activty B的CountDownTimer
中停止cancel()
(使用onPause
方法)并启动{{1}在Activty B的CountDownTimer
中保存了值(假设这是一个活动B代码):
onResume
答案 2 :(得分:0)
在活动之间切换时,尝试在Bundle的帮助下传递当前的倒计时时间。