Nlaniyadav / My-Programs

my programmes
1 stars 0 forks source link

Android app development task2 Stop watch #9

Open Nlaniyadav opened 8 months ago

Nlaniyadav commented 8 months ago

import android.app.Activity;

import android.os.Handler;

import android.view.View;

import android.os.Bundle;

import java.util.Locale;

import android.widget.TextView;

public class StopwatchActivity extends Activity {

// Use seconds, running and wasRunning respectively 

// to record the number of seconds passed, 

// whether the stopwatch is running and 

// whether the stopwatch was running 

// before the activity was paused. 

// Number of seconds displayed 

// on the stopwatch. 

private int seconds = 0; 

// Is the stopwatch running? 

private boolean running; 

private boolean wasRunning; 

@Override

protected void onCreate(Bundle savedInstanceState) 

{ 

    super.onCreate(savedInstanceState); 

    setContentView(R.layout.activity_stopwatch); 

    if (savedInstanceState != null) { 

        // Get the previous state of the stopwatch 

        // if the activity has been 

        // destroyed and recreated. 

        seconds 

            = savedInstanceState 

                  .getInt("seconds"); 

        running 

            = savedInstanceState 

                  .getBoolean("running"); 

        wasRunning 

            = savedInstanceState 

                  .getBoolean("wasRunning"); 

    } 

    runTimer(); 

}