Skip to content
This repository has been archived by the owner on Apr 2, 2018. It is now read-only.

Avoid Android crashes caused by onDestroy NullpointerExceptions #284

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/android/IonicKeyboard.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.ionic.keyboard;

import android.util.Log;
import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin;
Expand Down Expand Up @@ -128,7 +129,19 @@ else if ( pixelHeightDiff != previousHeightDiff && ( previousHeightDiff - pixelH

@Override
public void onDestroy() {
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list);
try {
rootView.getViewTreeObserver().removeOnGlobalLayoutListener(list);
} catch (Exception e) {
String msg = "";

if (rootView == null) msg += "rootView variable is null ";
if (rootView.getViewTreeObserver() == null) msg += "rootView.getViewTreeObserver() is null ";
if (list == null) msg += "list variable is null ";
if (msg.isEmpty()) msg = e.getMessage();

Log.w("IonicKeyboard", msg, e);
}
super.onDestroy();
}

}
Expand Down