user1223035
user1223035

Reputation: 241

How to identify if application is killed

How to identify if application is killed so that we can restart service by putting some alarm manager in Android at a specific interval of time ?

Upvotes: 0

Views: 1142

Answers (2)

MaciejGórski
MaciejGórski

Reputation: 22232

Service is automatically restarted after process is killed if you return START_STICKY from onStartCommand. You don't need AlarmManager for that.

Upvotes: 1

Lunchbox
Lunchbox

Reputation: 1550

Im not sure what you mean, but you could implement the onStop() and onDestroy() methods in your code then use a Toast in them eg.

@Override
    protected void onStop() {
        // TODO Auto-generated method stub
        super.onStop();
        Toast.makeText(this, "activity stopped", Toast.LENGTH_LONG).show();
    }

@Override
    protected void onDestroy() {
        // TODO Auto-generated method stub
        super.onDestroy();
        Toast.makeText(this, "activity destroyed", Toast.LENGTH_LONG).show();
    }

that should give you an indication when your activity goes through the life cycle. I should point out that android handles when your application is "killed"

Upvotes: 0

Related Questions