In Android, whenever there is change in orientation, previous activity instance get destroyed and new one get created. Below is a sequence of operation that happens with this said
onPause
onDestroy
onCreate
onResume
Now if a start any service such as window overlay service in onPause then it wouldnt start until orientation change happens. Due to this, onResume if check if started something already, it is not going to give any true result. One way is to check if the activity pause / destroy is happening due to configuration change, like the below
if(!isChangingConfigurations()) {
startService(new Intent(getApplicationContext(), OverlayService2.class));
}
references:
http://stackoverflow.com/questions/9620841/how-to-distinguish-between-orientation-change-and-leaving-application-android
No comments:
Post a Comment