public void finishLastActivity(@Nullable Thread uncaughtExceptionThread) { // Trying to solve https://github.com/ACRA/acra/issues/42#issuecomment-12134144 // Determine the current/last Activity that was started and close // it. Activity#finish (and maybe it's parent too). final Activity lastActivity = lastActivityManager.getLastActivity(); if (lastActivity != null) { final boolean isMainThread = uncaughtExceptionThread == lastActivity.getMainLooper().getThread(); if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Finishing the last Activity prior to killing the Process"); final Runnable finisher = () -> { lastActivity.finish(); if (ACRA.DEV_LOGGING) ACRA.log.d(LOG_TAG, "Finished " + lastActivity.getClass()); }; if (isMainThread) { finisher.run(); } else { lastActivity.runOnUiThread(finisher); } // A crashed activity won't continue its lifecycle. So we only wait if something else crashed if (!isMainThread) { lastActivityManager.waitForActivityStop(100); } lastActivityManager.clearLastActivity(); } }
/** * @return * @see android.content.ContextWrapper#getMainLooper() */ public Looper getMainLooper() { return mActivity.getMainLooper(); }
public ImageDownload(Activity _activity, ImageView imageView, String url) { activity = _activity; eventHandler = new EventHandler(activity.getMainLooper()); imageViews.add(imageView); urls.add(url); }
public ImageDownload(Activity _activity, ArrayList<ImageView> _imageViews, ArrayList<String> _urls) { activity = _activity; imageViews = new ArrayList<ImageView>(_imageViews); urls = new ArrayList<String>(_urls); eventHandler = new EventHandler(activity.getMainLooper()); }
public static void asyncGet(Request request, final Activity activity, final Callback callback) { Log.d(REQUEST_TAG, "async request Url: " + request.toString()); AppManager.getHttpClient().newCall(request).enqueue(new Callback() { Handler mainHandler = new Handler(activity.getMainLooper()); @Override public void onFailure(final Call call, final IOException e) { mainHandler.post(new Runnable() { @Override public void run() { callback.onFailure(call, e); } }); } @Override public void onResponse(final Call call, final Response response) throws IOException { mainHandler.post(new Runnable() { @Override public void run() { try { callback.onResponse(call, response); } catch (IOException e) { e.printStackTrace(); } } }); } }); }
v.setOrientation(LinearLayout.VERTICAL); v.setLayoutParams(linearparams); final Handler handler = new Handler(HookMethods.SnapContext.getMainLooper());
public static void asyncGet(Request request, final Activity activity, final Callback callback) { Log.d("fire3", "async request Url: " + request.urlString()); SailorCast.getHttpClient().newCall(request).enqueue(new Callback() { Handler mainHandler = new Handler(activity.getMainLooper()); @Override public void onFailure(final Request request, final IOException e) { mainHandler.post(new Runnable() { @Override public void run() { callback.onFailure(request,e); } }); } @Override public void onResponse(final Response response) throws IOException { mainHandler.post(new Runnable() { @Override public void run() { try { callback.onResponse(response); } catch (IOException e) { e.printStackTrace(); } } }); } }); }
@Before public void setUp() { delegate = mock(ShakeDelegate.class); activity = mock(Activity.class); fragmentManager = mock(FragmentManager.class); when(activity.getFragmentManager()).thenReturn(fragmentManager); when(activity.getApplicationContext()).thenReturn(activity); when(activity.getMainLooper()).thenReturn(Looper.getMainLooper()); when(delegate.getSensitivityLevel()).thenReturn(ShakeDelegate.SENSITIVITY_LIGHT); shaky = new Shaky(activity, delegate); shaky.setActivity(activity); }
public AppCompatDialog showProgressbar(Activity activity, long timeout, boolean cancelable) { final AppCompatDialog dialog = new AppCompatDialog(activity); dialog.setContentView(R.layout.dialog_progress); dialog.setCancelable(cancelable); dialog.setTitle("Progressing..."); ProgressBar progressBar = (ProgressBar) dialog.findViewById(R.id.progress); if (timeout > 0) { Handler handler = new Handler(activity.getMainLooper()); handler.postDelayed(new Runnable() { @Override public void run() { dialog.cancel(); dialog.dismiss(); } }, timeout); dialog.show(); } else { dialog.show(); } return dialog; }
@Override public void onActivityCreated(Bundle state) { super.onActivityCreated(state); mActivity = getActivity(); Intent intent = mActivity.getIntent(); fm = getFragmentManager(); mObserverCache = FileObserverCache.getInstance(); mUpdatePathListener = (onUpdatePathListener) mActivity; mActionController = new ActionModeController(mActivity); mActionController.setListView(mListView); if (sHandler == null) { sHandler = new Handler(mActivity.getMainLooper()); } initDirectory(state, intent); }