diff --git a/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java b/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java index 99f529bf..d67e3b57 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/search/BarcodeHelper.java @@ -19,7 +19,7 @@ package org.transdroid.core.gui.search; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; -import android.app.DialogFragment; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; @@ -27,6 +27,8 @@ import android.net.Uri; import org.transdroid.R; +import java.lang.ref.WeakReference; + public class BarcodeHelper { // A 'random' ID to identify QR-encoded settings scan intents @@ -69,18 +71,16 @@ public class BarcodeHelper { activity.startActivityForResult(intent, requestCode); } catch (Exception e) { // Can't start the bar code scanner, for example with a SecurityException or when ZXing is not present - new DialogFragment() { - public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { - return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(activity.getString(R.string.search_barcodescannernotfound)) - .setPositiveButton(android.R.string.yes, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - activity.startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); - } - }).setNegativeButton(android.R.string.no, null).create(); - } - }.show(activity.getFragmentManager(), "installscanner"); + final WeakReference intentStartContext = new WeakReference(activity); + new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(activity.getString(R.string.search_barcodescannernotfound)) + .setPositiveButton(android.R.string.yes, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (intentStartContext.get() != null) + intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, SCANNER_MARKET_URI)); + } + }).setNegativeButton(android.R.string.no, null).show(); } } diff --git a/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java b/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java index bdb065f5..b0a9fe02 100644 --- a/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java +++ b/app/src/main/java/org/transdroid/core/gui/search/FilePickerHelper.java @@ -21,12 +21,14 @@ import org.transdroid.R; import android.annotation.SuppressLint; import android.app.Activity; import android.app.AlertDialog; -import android.app.DialogFragment; +import android.content.Context; import android.content.DialogInterface; import android.content.DialogInterface.OnClickListener; import android.content.Intent; import android.net.Uri; +import java.lang.ref.WeakReference; + public class FilePickerHelper { public static final int ACTIVITY_FILEPICKER = 0x0000c0df; // A 'random' ID to identify file picker intents @@ -49,22 +51,17 @@ public class FilePickerHelper { // Start a file manager that can handle the PICK_FILE intent (specifically IO File Manager) activity.startActivityForResult(new Intent("org.openintents.action.PICK_FILE"), ACTIVITY_FILEPICKER); } catch (Exception e2) { - // Can't start the file manager, for example with a SecurityException or when IO File Manager is not - // present - new DialogFragment() { - public android.app.Dialog onCreateDialog(android.os.Bundle savedInstanceState) { - return new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) - .setMessage(activity.getString(R.string.search_filemanagernotfound)) - .setPositiveButton(android.R.string.yes, new OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - if (activity != null) - activity.startActivity(new Intent(Intent.ACTION_VIEW, - FILEMANAGER_MARKET_URI)); - } - }).setNegativeButton(android.R.string.no, null).create(); - }; - }.show(activity.getFragmentManager(), "installfilemanager"); + // Can't start the file manager, for example with a SecurityException or when IO File Manager is not present + final WeakReference intentStartContext = new WeakReference(activity); + new AlertDialog.Builder(activity).setIcon(android.R.drawable.ic_dialog_alert) + .setMessage(activity.getString(R.string.search_filemanagernotfound)) + .setPositiveButton(android.R.string.yes, new OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + if (intentStartContext.get() != null) + intentStartContext.get().startActivity(new Intent(Intent.ACTION_VIEW, FILEMANAGER_MARKET_URI)); + } + }).setNegativeButton(android.R.string.no, null).show(); } } }