views:

28

answers:

1

Hi guys, I have 3 activity in my application. My first activity (Main) has 2 button that starts other activities (One & Two). The One Activity starts a countdown timer on UI. When I click back button Android closes this activity and when I re-open activity, my timer is resetted.

I try also overriding:

    public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        moveTaskToBack(true);
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

and it's works correctly but when I re-open the Main Activity, Android shows me my timer activity. How can I resolve this problem?

+1  A: 

Where do you reset your timer? If an activity is in the background it's not destroyed but paused. It'll not go through onCreate unless it's destroyed (finished). If you want to reset the timer each time the activity comes to the foreground, use the onResume() method:

@Override
protected void onResume() {   
    super.onResume();     

    //reset timer
}

Read here: android life cycle

If this is not the problem and you already consider the activity life cycle states, then paste some more code.

Maragues
Hi Maragues,thanks for your reply. My problem is inverted. I don't want my timer resetted when I reopen this activity. So, when i click back button, my activity is destroyed from android.
Cecco
Maragues