coderslay
coderslay

Reputation: 14370

I need to check that application has been closed or in background in android

I need to know if we press home or back button in android... can we close the application activity? If not than how can we know that the app activity is running or not?

Upvotes: 2

Views: 228

Answers (1)

kannappan
kannappan

Reputation: 2250

You can close application when You press the home or back button.

try this code

  @Override

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if(KeyEvent.KEYCODE_BACK==keyCode || KeyEvent.KEYCODE_HOME==keycode)
    {   

        finish();
    }       
    return super.onKeyDown(keyCode, event);
}

Upvotes: 1

Related Questions