aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/CgeoApplication.java
diff options
context:
space:
mode:
Diffstat (limited to 'main/src/cgeo/geocaching/CgeoApplication.java')
-rw-r--r--main/src/cgeo/geocaching/CgeoApplication.java48
1 files changed, 47 insertions, 1 deletions
diff --git a/main/src/cgeo/geocaching/CgeoApplication.java b/main/src/cgeo/geocaching/CgeoApplication.java
index 09aee93..2ee91be 100644
--- a/main/src/cgeo/geocaching/CgeoApplication.java
+++ b/main/src/cgeo/geocaching/CgeoApplication.java
@@ -10,6 +10,12 @@ import rx.functions.Action1;
import rx.observables.ConnectableObservable;
import android.app.Application;
+import android.os.Environment;
+import android.view.ViewConfiguration;
+
+import java.io.IOException;
+import java.lang.Thread.UncaughtExceptionHandler;
+import java.lang.reflect.Field;
public class CgeoApplication extends Application {
@@ -22,6 +28,31 @@ public class CgeoApplication extends Application {
private volatile IGeoData currentGeo = null;
private volatile float currentDirection = 0.0f;
+ static {
+ final UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();
+
+ Thread.setDefaultUncaughtExceptionHandler(new UncaughtExceptionHandler() {
+
+ @Override
+ public void uncaughtException(final Thread thread, final Throwable ex) {
+ Log.e("UncaughtException", ex);
+ Throwable exx = ex;
+ while (exx.getCause() != null) {
+ exx = exx.getCause();
+ }
+ if (exx.getClass().equals(OutOfMemoryError.class)) {
+ try {
+ Log.e("OutOfMemory");
+ android.os.Debug.dumpHprofData(Environment.getExternalStorageDirectory().getPath() + "/dump.hprof");
+ } catch (final IOException e) {
+ Log.e("Error writing dump", e);
+ }
+ }
+ defaultHandler.uncaughtException(thread, ex);
+ }
+ });
+ }
+
public CgeoApplication() {
setInstance(this);
}
@@ -35,6 +66,21 @@ public class CgeoApplication extends Application {
}
@Override
+ public void onCreate() {
+ try {
+ final ViewConfiguration config = ViewConfiguration.get(this);
+ final Field menuKeyField = ViewConfiguration.class.getDeclaredField("sHasPermanentMenuKey");
+
+ if (menuKeyField != null) {
+ menuKeyField.setAccessible(true);
+ menuKeyField.setBoolean(config, false);
+ }
+ } catch (final Exception ex) {
+ // Ignore
+ }
+ }
+
+ @Override
public void onLowMemory() {
Log.i("Cleaning applications cache.");
DataStore.removeAllFromCache();
@@ -69,7 +115,7 @@ public class CgeoApplication extends Application {
}
public IGeoData currentGeo() {
- return currentGeo != null ? currentGeo : geoDataObservable().toBlockingObservable().first();
+ return currentGeo != null ? currentGeo : geoDataObservable().toBlocking().first();
}
public float currentDirection() {