Why my chronometer wouldn't stop after I've told it to?
I have found out that it seems to be isolated to the tablet I have tested it on (7 inch Galaxy Tab
). I have no idea why it would work on my phone yet not work on the tablet. The Chronometer
is set up the same in both layouts (since I am using different layouts for the different screen sizes).
Here is how the Chronometer
is handled in the class:
this.chrono = (Chronometer) findViewById(R.id.calling_crono);
chrono.setOnChronometerTickListener(new OnChronometerTickListener() {
public void onChronometerTick(Chronometer chronometer) {
String currentTime= chrono.getText().toString();
if(currentTime.equals("00:20"))
{
chrono.stop();
Intent intent = new Intent(QuizActivity.this, ResultActivity.class);
Bundle b = new Bundle();
int end = -5;
b.putInt("score", score);
b.putInt("end", end);
intent.putExtras(b);
startActivity(intent);
finish();
}
}
});
public void startCrono() {
chrono.setBase(SystemClock.elapsedRealtime());
chrono.start();
}
Here is how it is set up in the normal-size screen:
<Chronometer
android:id="@+id/calling_crono"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="#000099"
android:textStyle="bold"
android:textSize="20sp"/>
And here it is in the large-size screen:
<Chronometer
android:id="@+id/calling_crono"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="50sp"
android:textColor="#000099"
android:textStyle="bold" />
The basic problem is that on the phone it works as normal, which is to move on after 20 seconds, but on the tablet it won't stop and keeps going ahead. Is there some reason why this works on my phone (Xperia
), but not on the tablet. The only thing I can think off is the fact that they use different xml
layout files.