System.exit(0) causes the Activity quit quickly when the app starts
<p>I met a problem, <code>System.exit(0)</code> cause the Activity quit quickly when the app start:</p>

<p>in a project, i see that use <code>System.exit(0)</code> to realize the complete exit of app, and i do that, but the activity did not go through its life cycle in project, so i use the following methods:</p>

<pre><code>public class App extends Application {
    private int mLock = 0;
    @Override
    public void onCreate() {
        registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
            @Override
            public void onActivityCreated(Activity activity, Bundle savedInstanceState) {
                mLock++;
            }
            @Override
            public void onActivityDestroyed(Activity activity) {
                try {
                    //Simulation Activity Destroyed too time consuming and increase the probability of problems

                    Thread.sleep(300);
                } catch (InterruptedException e) {
                }
                mLock--;
                if(mLock&lt;=0){
                    exit();
                }
            }
            @Override
            public void onActivityStopped(Activity activity) {}
            @Override
            public void onActivityStarted(Activity activity) {}
            @Override
            public void onActivitySaveInstanceState(Activity activity, Bundle outState) {}
            @Override
            public void onActivityResumed(Activity activity) {}
            @Override
            public void onActivityPaused(Activity activity) {}

        });
    }

    public void exit() {
        System.exit(0);
    }

}
</code></pre>

<p>but, such, the problem arise, if i quit the last activity (quit app), and immediately and quickly start app, then Activity quit but it did not start complete (flash quit).</p>

<p><strong>edit</strong>
what i want to do is quit app when all activity is destroyed.but,there is a problem:when app want to finish its own process,all activity are destroyed,but when haven't even call System. Exit (),launched a activity,then call System.exit(),at this time there will be a flash quit,How to avoid this problem？</p>

<p>Well, but my purpose is to end the application process (some needs, not consider is it should do), just in the after of the default startup activity destroy, rather than in any other activity to do the end of this operation process, I use the above method in order to ensure that all start activity will be able to complete its life cycle in the app. But that had the problem as description, this should be multithreaded synchronization problem, but I have sleep in the application, why it can created activity during sleep? Don't application and activity is not the same thread, but their thread id is 1.</p>
