Note that there are some explanatory texts on larger screens.

plurals
  1. POIs System.exit(0) really that dangerous?
    primarykey
    data
    text
    <p>An application background service updates sqlite database. Therefore my activities are becoming outdated. Activity intents also contain outdated params so onCreate, onResume will crash the application. An easiest solution is to restart whole application. I don't want to add IFs to all onCreate, onResume methods in all activities to handle one special case.</p> <p>I noticed that <a href="https://github.com/ACRA/acra" rel="nofollow">ACRA</a> has following code executed after an exception has been handled.</p> <pre><code>android.os.Process.killProcess(android.os.Process.myPid()); System.exit(10); </code></pre> <p>However many people discourage use of <code>System.exit(0)</code>. Is <code>System.exit(0)</code> really that dangerous for an Android application data integrity? Of course my code will close the database before existing.</p> <p><strong>Update:</strong></p> <p>I known how to use <code>finish()</code>, content providers, send broadcasts, read many answers here on SO, etc. However each of these approaches requires additional thousands lines of code. I implemented solution with <code>System.exit(0)</code> in ten minutes. The restart is so fast that it is indistinguishable from ordinary startActivity action. The db update/restart is done after longer user inactivity so the app is already suspended by the system. My app doesn't require real time syncing. During tests the application behaves correctly. This is quick and dirty solution.</p> <p>Therefore I asked the question about possible side effects of <code>System.exit(0)</code>. Not how I can do the design differently. I know that current design is not perfect.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload