'Why does chronometer begin to count up when an Activity starts?
When I launch the app with the widget Chronometer, this counts up itself parallel to the android activity when this is botted . I put a button for example and I added in the listener the method chronometer.start(). When I press the button, the time had already counted. It is like both Activity and Chronometer start parallel without any handle for the user. I was looking for solutions and I founded it how to implement and manage but I will know the reason why this happen. This is my code:
public class MainActivity extends AppCompatActivity {
Chronometer chronometer;
Button button_record;
Button button_stop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button_record = (Button)findViewById(R.id.button_record);
button_stop = (Button)findViewById(R.id.button_stop);
chronometer = (Chronometer)findViewById(R.id.chronometer_mic);
button_record.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
chronometer.start(); // Here the time was counted up when the app is booted or Activity
}
});
button_stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
chronometer.stop();
}
});
}
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
