{"id":1523,"date":"2022-08-30T15:17:14","date_gmt":"2022-08-30T15:17:14","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/11\/26\/situations-when-a-services-ondestroy-method-doesnt-get-called-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:17:14","modified_gmt":"2022-08-30T15:17:14","slug":"situations-when-a-services-ondestroy-method-doesnt-get-called-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/situations-when-a-services-ondestroy-method-doesnt-get-called-collection-of-common-programming-errors\/","title":{"rendered":"Situations when a Service&#39;s onDestroy() method doesn&#39;t get called?-Collection of common programming errors"},"content":{"rendered":"<blockquote>\n<p>I&#8217;m aware that a Service&#8217;s onDestroy() method may never be called but can someone tell me when such a scenario might occur?<\/p>\n<\/blockquote>\n<p>Here are three off the top of my head:<\/p>\n<ul>\n<li>\n<p>If the user Force Stops you from the Settings app<\/p>\n<\/li>\n<li>\n<p>If Android needs RAM in a hurry (e.g., to process an incoming phone call) and elects to terminate your process to free up that RAM<\/p>\n<\/li>\n<li>\n<p>You terminate the process from DDMS<\/p>\n<\/li>\n<\/ul>\n<p>Also, if your service crashes with an unhandled exception somewhere, Android may consider the service to be defunct and skip <code>onDestroy()<\/code>. I&#8217;m not sure about this one, as I haven&#8217;t specifically tried it.<\/p>\n<blockquote>\n<p>But I&#8217;m wondering if it&#8217;s possible for a service to &#8220;go away&#8221; without onDestroy() being called, while the observers it created would live on and continue to receive changes.<\/p>\n<\/blockquote>\n<p>Other than the unhandled-exception possibility I mention above, I am reasonably certain that if the process will be terminated in the conditions where <code>onDestroy()<\/code> is not called.<\/p>\n<p id=\"rop\"><small>Originally posted 2013-11-26 18:03:41. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m aware that a Service&#8217;s onDestroy() method may never be called but can someone tell me when such a scenario might occur? Here are three off the top of my head: If the user Force Stops you from the Settings app If Android needs RAM in a hurry (e.g., to process an incoming phone call) [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1523","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1523"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1523\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}