From 626119ae3b746560bed9ffa31043a5f5aa73fa12 Mon Sep 17 00:00:00 2001 From: Bryce Curtis Date: Tue, 5 Apr 2011 15:42:25 -0500 Subject: [PATCH] Bug 126: NullPointerException in onDestroy() --- framework/src/com/phonegap/DroidGap.java | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/framework/src/com/phonegap/DroidGap.java b/framework/src/com/phonegap/DroidGap.java index 74102e00..547c1668 100755 --- a/framework/src/com/phonegap/DroidGap.java +++ b/framework/src/com/phonegap/DroidGap.java @@ -601,6 +601,10 @@ public class DroidGap extends PhonegapActivity { */ protected void onPause() { super.onPause(); + if (this.appView == null) { + return; + } + // Send pause event to JavaScript this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};"); @@ -621,6 +625,9 @@ public class DroidGap extends PhonegapActivity { */ protected void onResume() { super.onResume(); + if (this.appView == null) { + return; + } // Send resume event to JavaScript this.appView.loadUrl("javascript:try{PhoneGap.onResume.fire();}catch(e){};"); @@ -649,6 +656,8 @@ public class DroidGap extends PhonegapActivity { public void onDestroy() { super.onDestroy(); + if (this.appView != null) { + // Make sure pause event is sent if onPause hasn't been called before onDestroy this.appView.loadUrl("javascript:try{PhoneGap.onPause.fire();}catch(e){};"); @@ -664,6 +673,7 @@ public class DroidGap extends PhonegapActivity { if (this.callbackServer != null) { this.callbackServer.destroy(); } + } } /** @@ -1099,6 +1109,9 @@ public class DroidGap extends PhonegapActivity { */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { + if (this.appView == null) { + return super.onKeyDown(keyCode, event); + } // If back key if (keyCode == KeyEvent.KEYCODE_BACK) {