2

I'm newbee on android, and already read Android app start and end event and Android onClose event but haven't found the answer.

I'm developing a simple application - flashlight. And I want to release camera LED when application (not activity) is ended. Android has Application onCreate event, but doesn't have an appropriate onEnd/onExit event. Activity OnDestroy event is not the case, because it is raised each time the device changes its orientation.

Does Application have onEnd event?

Community
  • 1
  • 1
Nicolas
  • 74
  • 11

2 Answers2

2

Does Application have onEnd event?

No. Mostly, that is because applications do not "end". They are either in the foreground, in the background, or their processes are terminated.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
1

I found a way to do it:

You have a listener onPause() that is triggered when your app goes in background. And usually when you kill your app in the task manager...your app goes in background for a few sec. And that is the only way I found to do this. For my example I have an app that plays a music automatically at launch. (Even if mobile is in silent mode).

I use onPause() to stop music and set original volume back to silent.

protected void onPause(){
    super.onPause();
    mp.pause(); //that is mediaplayer pause
    audioManager.setStreamVolume(AudioManager.STREAM_MUSIC,originalVol, 0);
} //set volume to its original state
VC1
  • 1,660
  • 4
  • 25
  • 42