Devam03 February 2016

Sum Of Total Time Taken Of Timer

I am making a game.

Lets say that it has 2 levels. I have a TIMER in both which works properly. The code for timer:

public Timer t;
public int TimeCounter = 0;
t = new Timer();
t.scheduleAtFixedRate(new TimerTask() {
    @Override
    public void run() {
        // TODO Auto-generated method stub
        runOnUiThread(new Runnable() {
            public void run() {
                TextView t = (TextView)findViewById(R.id.txtcount);
                t.setText(String.valueOf(TimeCounter));
                TimeCounter++;
            }
        });
    }
}, 1000, 1000);

Now in my 3rd activity i want the total time (Adding the first activity's and second activity's time taken) to be shown.

Also, I want to save the time the user took as the high score. And then when the user takes less time than the highest score, the previous will get deleted and the new will be saved

I would appreciate your help.Thanks

Answers


Rohit5k2 February 2016

Make TimeCounter static

public static int TimeCounter = 0;

Now you can increment it in both of your activities like (in second activity it will retain values from first activity)

ActivityOne.TimeCounter++;

Wherever you want to get its value you can get it easily.

Post Status

Asked in February 2016
Viewed 3,284 times
Voted 4
Answered 1 times

Search




Leave an answer