Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <ol> <li><p>Best solution would be instead of using Static data, use <code>Shared Preferences</code> or store data in a <code>Database</code> and if any <code>uncaught Exception</code> occurs, show a message like <code>Application has crashed and a report is sent to the admin</code> and then restart the Activity that caused the Crash. This way user can continue using the application.</p></li> <li><p>Do the same but instead of restarting the Activity which caused the Exception restart the application.</p></li> </ol> <p>create a class used to handle <code>unCaughtException</code></p> <pre><code>public class MyExceptionHandler implements java.lang.Thread.UncaughtExceptionHandler { private final Context myContext; private final Class&lt;?&gt; myActivityClass; public MyExceptionHandler(Context context, Class&lt;?&gt; c) { myContext = context; myActivityClass = c; } public void uncaughtException(Thread thread, Throwable exception) { StringWriter stackTrace = new StringWriter(); exception.printStackTrace(new PrintWriter(stackTrace)); System.err.println(stackTrace);// You can use LogCat too Intent intent = new Intent(myContext, myActivityClass); String s = stackTrace.toString(); //you can use this String to know what caused the exception and in which Activity intent.putExtra("uncaughtException", "Exception is: " + stackTrace.toString()); intent.putExtra("stacktrace", s); myContext.startActivity(intent); //for restarting the Activity Process.killProcess(Process.myPid()); System.exit(0); } } </code></pre> <p>and in every Activity create an Object of this class and set it as the <code>DefaultUncaughtExceptionHandler</code></p> <pre><code> Thread.setDefaultUncaughtExceptionHandler(new MyExceptionHandler(this, YourCurrentActivity.class)); </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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