Catch all throwable from startActivity()

This commit is contained in:
seven332 committed 2018-12-21 18:04:23 +08:00
1 parent 4b1c516b3e
commit 8af786e687
4 files changed
+23 -10

No files matched your search

@@ -16,7 +16,6 @@
package com.hippo.ehviewer;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@@ -24,11 +23,11 @@ import android.provider.Browser;
import android.support.annotation.NonNull;
import android.text.TextUtils;
import android.widget.Toast;
import com.hippo.ehviewer.client.EhUrlOpener;
import com.hippo.ehviewer.ui.MainActivity;
import com.hippo.scene.Announcer;
import com.hippo.scene.StageActivity;
import com.hippo.util.ExceptionUtils;
public final class UrlOpener {
@@ -61,7 +60,8 @@ public final class UrlOpener {
intent.putExtra(Browser.EXTRA_APPLICATION_ID, context.getPackageName());
try {
context.startActivity(intent);
} catch (ActivityNotFoundException e) {
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
Toast.makeText(context, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
}
}
@@ -66,6 +66,7 @@ import com.hippo.glgallery.GalleryView;
import com.hippo.glgallery.SimpleAdapter;
import com.hippo.glview.view.GLRootView;
import com.hippo.unifile.UniFile;
import com.hippo.util.ExceptionUtils;
import com.hippo.util.SystemUiHelper;
import com.hippo.widget.ColorView;
import com.hippo.yorozuya.AnimationUtils;
@@ -895,7 +896,13 @@ public class GalleryActivity extends EhActivity implements SeekBar.OnSeekBarChan
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType(mimeType);
startActivity(Intent.createChooser(intent, getString(R.string.share_image)));
try {
startActivity(Intent.createChooser(intent, getString(R.string.share_image)));
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
Toast.makeText(this, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
}
}
private void saveImage(int page) {
@@ -22,8 +22,9 @@ import android.content.res.TypedArray;
import android.preference.Preference;
import android.util.AttributeSet;
import android.util.Log;
import android.widget.Toast;
import com.hippo.ehviewer.R;
import com.hippo.util.ExceptionUtils;
public class ActivityPreference extends Preference {
@@ -68,6 +69,11 @@ public class ActivityPreference extends Preference {
Context context = getContext();
Intent intent = new Intent(context, mActivityClazz);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intent);
try {
context.startActivity(intent);
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
Toast.makeText(context, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
}
}
}
@@ -19,7 +19,6 @@ package com.hippo.util;
import android.app.Activity;
import android.app.Dialog;
import android.app.Service;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
@@ -28,7 +27,6 @@ import android.support.annotation.Nullable;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;
import com.hippo.ehviewer.R;
public class AppHelper {
@@ -47,7 +45,8 @@ public class AppHelper {
try {
from.startActivity(i);
return true;
} catch (ActivityNotFoundException e) {
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
Toast.makeText(from, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
return false;
}
@@ -63,7 +62,8 @@ public class AppHelper {
try {
from.startActivity(chooser);
return true;
} catch (ActivityNotFoundException e) {
} catch (Throwable e) {
ExceptionUtils.throwIfFatal(e);
Toast.makeText(from, R.string.error_cant_find_activity, Toast.LENGTH_SHORT).show();
return false;
}