Contents of the file is empty when stop button is clicked
<p>My problem is that the file is empty after clicking stop button but only when the time changes e.g. when i click start button at 16:49:39 and then stop button at 16:49:57 then the file is empty. But when I click stop button 16:50:01 then the file saves with data.Please tell my why this  happens ? And how to solve this. Below you can see the code from my application:</p>

<p>OnClick code:</p>

<pre><code>   @Override
public void onClick(View v) {
    switch (v.getId()) {
        case R.id.startButton:
            stoper.start();

            try {
                writer = new CSVwriter(dateFormat.format(date));
            } catch (IOException e) {
                e.printStackTrace();  
            }
            handler.postDelayed(UpdateView, 120);
            break;
        case R.id.stopButton:
            stoper.stop();

            try {
                writer.closeFile();
            } catch (IOException e) {
                e.printStackTrace();  
            }
            break;
    }
}

private Runnable UpdateView = new Runnable() {
    public void run() {
        timerText.setText(stoper.toString());
        pulsText.setText(""+accelerationX);

        try {
             writer.insertLine(new DataObject(stoper.toString(), accelerationX, accelerationY, accelerationZ));
         } catch (IOException e) {
            e.printStackTrace();
        }

        handler.postDelayed(UpdateView, 100);
        }
};
</code></pre>

<p>OnCreate code:</p>

<pre><code>@Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        View startBtn = findViewById(R.id.startButton);
        startBtn.setOnClickListener(this);
        View stopBtn = findViewById(R.id.stopButton);
        stopBtn.setOnClickListener(this);


        handler = new Handler();


    }
</code></pre>
