@@ -2840,44 +2840,21 @@ public void create() {
2840
2840
2841
2841
}
2842
2842
2843
- /*
2844
- // No need for these two, as explicit app exit is not required on Android, read
2845
- // this discussion:
2846
- // http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238
2847
-
2848
- // Call to safely exit the sketch when finished. For instance,
2849
- // to render a single frame, save it, and quit.
2850
2843
public void exit () {
2851
- if (surface.isStopped()) {
2852
- // exit immediately, stop() has already been called,
2853
- // meaning that the main thread has long since exited
2854
- exitActual();
2855
-
2856
- } else if (looping) {
2857
- // stop() will be called as the thread exits
2858
- finished = true;
2859
- // tell the code to call exitActual() to do a System.exit()
2860
- // once the next draw() has completed
2861
- exitCalled = true;
2862
-
2863
- } else if (!looping) {
2864
- // if not looping, shut down things explicitly,
2865
- // because the main thread will be sleeping
2866
- dispose();
2867
-
2868
- // now get out
2869
- exitActual();
2870
- }
2871
- }
2872
-
2873
- public void exitActual() {
2874
- try {
2875
- System.exit(0);
2876
- } catch (SecurityException e) {
2877
- // don't care about applet security exceptions
2844
+ if (getSurface ().getComponent ().isService ()) {
2845
+ PGraphics .showWarning ("This sketch is running as a live wallpaper or a watch face, and cannot be stopped with exit().\n " +
2846
+ "Use the corresponding selector on the device to change the current wallpaper or watch face." );
2847
+ } else {
2848
+ // This is the correct way to stop the sketch programmatically, according to the developer's docs:
2849
+ // https://developer.android.com/reference/android/app/Activity.html#onDestroy()
2850
+ // https://developer.android.com/reference/android/app/Activity.html#finish()
2851
+ // and online discussions:
2852
+ // http://stackoverflow.com/questions/2033914/quitting-an-application-is-that-frowned-upon/2034238
2853
+ // finish() it will trigger an onDestroy() event, which will translate down through the
2854
+ // activity hierarchy and trigger stopping Processing's animation thread, etc.
2855
+ getActivity ().finish ();
2878
2856
}
2879
2857
}
2880
- */
2881
2858
2882
2859
/**
2883
2860
* Called to dispose of resources and shut down the sketch.
0 commit comments