RecipeA.java
public void onTimerClicked(View v) {
Intent intent = new Intent(getApplicationContext(), TimerActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivityForResult(intent, 0);
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(resultCode == RESULT_OK && requestCode == 0) {
RecipeA.mViewPager.setCurrentItem(6);
}
else
RecipeA.mViewPager.setCurrentItem(4);
}
TimerActivity.java
public class TimerActivity extends Activity{
private CountDownTimer countDownTimer;
private boolean timerHasStarted = false;
private Button button;
private TextView tvtimer;
private long starttime = 1800 * 1000;
private final long interval = 1 * 1000;
private int secs;
private int minutes;
private int seconds;
private long remainingmillisec;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
layoutParams.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
layoutParams.dimAmount = 0.7f;
getWindow().setAttributes(layoutParams);
setContentView(R.layout.activity_timer);
tvtimer = (TextView) findViewById(R.id.tv_timer);
button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View arg0) {
if (!timerHasStarted) {
Log.d("Starttime", "KK" + starttime);
countDownTimer = new MyCountDownTimer(starttime, interval);
secs = (int) (starttime / 1000);
minutes = (secs % (60 * 60) / 60);
seconds = (secs % (60 * 60) % 60);
tvtimer.setText("" + String.format("%02d", minutes) + ":" + String.format("%02d", seconds));
countDownTimer.start();
timerHasStarted = true;
button.setText("멈추기");
} else {
starttime = remainingmillisec;
Log.d("StoTime", "KK" + starttime);
countDownTimer.cancel();
timerHasStarted = false;
button.setText("시작하기");
}
}
});
}
public class MyCountDownTimer extends CountDownTimer {
public MyCountDownTimer(long starttime, long interval) {
super(starttime, interval);
}
@Override
public void onFinish() {
Intent intent = getIntent();
tvtimer.setText("시간종료");
setResult(RESULT_OK, intent);
finish();
}
public void resume(){}
@Override
public void onTick(long millisUntilFinished) {
remainingmillisec = millisUntilFinished;
secs = (int)(millisUntilFinished / 1000);
minutes = (secs%(60*60)/60);
seconds = (secs % (60 * 60) % 60);
tvtimer.setText("" + String.format("%02d", minutes) + ":" + String.format("%02d", seconds));
}
}
}
requestCode 체크 이후에도 setCurrentItem(4)가 실행됩니다 ..
- 원하는 것은 타이머 버튼이 눌러지면 타이머가 자동으로 실행되고,
시간이 종료되어 타이머 액티비티가 종료되면 setCurrentItem(6)으로 이동하게 하고 싶습니다
다시 한 번 조언 부탁드립니다 ㅠㅠㅠㅠㅠㅠ