Example usage for android.app Activity isFinishing

List of usage examples for android.app Activity isFinishing

Introduction

In this page you can find the example usage for android.app Activity isFinishing.

Prototype

public boolean isFinishing() 

Source Link

Document

Check to see whether this activity is in the process of finishing, either because you called #finish on it or someone else has requested that it finished.

Usage

From source file:com.yerdy.services.Yerdy.java

/**
 * Confirms focus of application for Yerdy pause/resume, should be called from activity onWindowFocusChanged()
 * /*from w  w w .ja  v a2  s  .c  o  m*/
 * <pre>{@code
 *&#064;Override
 *public void onWindowFocusChanged(boolean hasFocus) {
 *  super.onWindowFocusChanged(hasFocus);
 *  Yerdy.getInstance().onWindowFocusChanged(hasFocus, this);
 *}</pre>
 * 
 * @param hasFocus if activity has focus
 * @param activity current activity
 * @category Application Life Cycle
 */
public void onWindowFocusChanged(boolean hasFocus, Activity activity) {
    if (hasFocus && !activity.isFinishing())
        activate(activity, true);
    else
        deactivate();
}

From source file:com.yerdy.services.Yerdy.java

/**
 * Resumes Yerdy tracking of current application, should be called from activity onResume(), also confirms application is in focus
 * //w ww .  j av  a  2s . c  om
 * <pre>{@code
 *&#064;Override
 *protected void onResume() { 
 *  super.onResume();
 *  Yerdy.getInstance().onResume(this);
 *}</pre>
 * 
 * @param activity current activity
 * @category Application Life Cycle
 */
public void onResume(Activity activity) {
    boolean hasFocus = activity.hasWindowFocus();
    boolean finishing = activity.isFinishing();
    if (hasFocus && !finishing)
        activate(activity, true);
}

From source file:com.yerdy.services.Yerdy.java

private boolean internalShowMessage(Activity activity, String placement, boolean first) {
    if (activity == null || activity.isFinishing())
        return false;

    if (_activeMessage != null) {
        if (_activeMessage.isVisible() || !_activeMessage.hasReportedAction())
            return false;
    }// w w w. ja  va  2 s  .co m

    YRDMessage msgData = getMessageForPlacement(placement);
    if (msgData == null)
        return false;

    YRDMessagePreseneter msg = new YRDMessagePreseneter(msgData, activity.getApplicationContext());
    msg.setMessageDelegate(new PresenterDelegate());

    if (first) {
        _messagesPresentedInRow = 1;
        _didDismissMessage = false;
    } else {
        _messagesPresentedInRow++;
    }

    _currentPlacement = placement;
    msg.show(activity);
    _activeMessage = msg;

    synchronized (_messages) {
        _messages.remove(msgData);
    }

    _historyTracker.addMessage(Integer.toString(msgData.id));

    return true;
}

From source file:com.jaspersoft.android.jaspermobile.test.acceptance.viewer.WebViewInjector.java

@Override
public void onActivityLifecycleChanged(Activity activity, Stage stage) {
    ComponentName targetComponentName = new ComponentName(activity, mClass.getName());

    ComponentName currentComponentName = activity.getComponentName();
    if (!currentComponentName.equals(targetComponentName))
        return;//www. j a  v a 2  s. com

    switch (stage) {
    case RESUMED:
        // As soon as, we are trying to register inject of idle resource during on Resume.
        // We need to do this only first time. And yes, I know it is dirty. Any suggestions welcomed :)
        if (!mInjected) {
            FragmentActivity htmlViewerActivity = (FragmentActivity) activity;
            WebViewFragment fragment = (WebViewFragment) htmlViewerActivity.getSupportFragmentManager()
                    .findFragmentByTag(WebViewFragment.TAG);
            ViewGroup holder = (ViewGroup) fragment.getView().findViewById(R.id.webViewPlaceholder);
            // We need to wait for the activity to be created before getting a reference
            // to the webview
            JSWebView webView = (JSWebView) holder.getChildAt(0);

            mWebViewIdlingResource.inject(webView);
            mInjected = true;
        }
        break;
    case STOPPED:
        // Clean up reference
        if (activity.isFinishing())
            mWebViewIdlingResource.clear();
        break;
    default: // NOP
    }
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static void settingPermission(@NonNull Activity activity) {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.System.canWrite(activity)) {
        MaterialDialog.Builder builder = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.writesetting).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override/*from  ww  w .  j  a va 2s.  c o  m*/
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, WRITESETTINGS);
                            } else {
                                Toast.makeText(activity, "No app found to handle settings write permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setSettings(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            builder.show();
        }
    }
}

From source file:com.rks.musicx.misc.utils.permissionManager.java

public static void widgetPermission(@NonNull Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M && !Settings.canDrawOverlays(activity)) {
        MaterialDialog.Builder dialog = new MaterialDialog.Builder(activity).title(R.string.permissions_title)
                .content(R.string.draw_over_permissions_message).positiveText(R.string.btn_continue)
                .negativeText(R.string.btn_cancel).autoDismiss(true)
                .onPositive(new MaterialDialog.SingleButtonCallback() {
                    @Override//from  w  w w.  j a  v a 2  s.  c  om
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
                            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
                                    Uri.fromParts("package", activity.getPackageName(), null));
                            if (Helper.isActivityPresent(activity, intent)) {
                                activity.startActivityForResult(intent, OVERLAY_REQ);
                            } else {
                                Toast.makeText(activity,
                                        "No app found to handle floating widget enable permission",
                                        Toast.LENGTH_SHORT).show();
                            }
                        }
                    }
                }).onNegative(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Toast.makeText(activity, R.string.toast_permissions_not_granted, Toast.LENGTH_SHORT)
                                .show();
                        dialog.dismiss();
                    }
                }).neutralText("Never show again").onNeutral(new MaterialDialog.SingleButtonCallback() {
                    @Override
                    public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
                        Extras.getInstance().setWidgetTrack(true);
                        dialog.dismiss();
                    }
                });
        if (activity.hasWindowFocus() || !activity.isFinishing()) {
            dialog.show();
        }
    }
}

From source file:com.benefit.buy.library.http.query.callback.AbstractAjaxCallback.java

/**
 * Starts the async process. If activity is passed, the callback method will not be invoked if the activity is no
 * longer in use. Specifically, isFinishing() is called to determine if the activity is active.
 * @param act activity//w w  w.  j av  a 2 s  . c o m
 */
public void async(Activity act) {
    if (act.isFinishing()) {
        AQUtility.warn("Warning", "Possible memory leak. Calling ajax with a terminated activity.");
    }
    if (type == null) {
        AQUtility.warn("Warning", "type() is not called with response type.");
        return;
    }
    this.act = new WeakReference<Activity>(act);
    async((Context) act);
}

From source file:com.benefit.buy.library.http.query.callback.AbstractAjaxCallback.java

private boolean isActive() {
    if (act == null) {
        return true;
    }//from   w w  w .  j  av a2  s.c o m
    Activity a = act.get();
    if ((a == null) || a.isFinishing()) {
        return false;
    }
    return true;
}

From source file:com.smartnsoft.droid4me.app.ActivityController.java

/**
 * Dispatches the exception to the {@link ActivityController.ExceptionHandler}, and invokes the right method depending on its nature.
 * /*from  w  w w.  ja v  a  2 s .c  o  m*/
 * <p>
 * The framework is responsible for invoking that method every time an unhandled exception is thrown. If no
 * {@link ActivityController#registerExceptionHandler(ExceptionHandler) exception handler is registered}, the exception will be only logged, and the
 * method will return {@code false}.
 * </p>
 * 
 * <p>
 * Note that this method is {@code synchronized}, which prevents it from being invoking while it is already being executed, and which involves that
 * only one {@link Throwable} may be handled at the same time.
 * </p>
 * 
 * @param isRecoverable
 *          indicates whether the application is about to crash when the exception has been triggered
 * @param context
 *          the context that originated the exception ; may be {@code null}
 * @param component
 *          when not {@code null}, this will be the {@link android.app.Fragment} the exception has been thrown from
 * @param throwable
 *          the reported exception
 * @return {@code true} if the exception has been handled ; in particular, if no {@link ActivityController#getExceptionHandler() exception handled
 *         has been set}, returns {@code false}
 */
public synchronized boolean handleException(boolean isRecoverable, Context context, Object component,
        Throwable throwable) {
    if (exceptionHandler == null) {
        if (log.isWarnEnabled()) {
            log.warn(
                    "Detected an exception which will not be handled during the processing of the context with name '"
                            + (context == null ? "null" : context.getClass().getName()) + "'",
                    throwable);
        }
        return false;
    }
    final Activity activity;
    if (context instanceof Activity) {
        activity = (Activity) context;
    } else {
        activity = null;
    }
    try {
        if (activity != null && throwable instanceof BusinessObjectUnavailableException) {
            // Should only occur with a non-null activity
            final BusinessObjectUnavailableException exception = (BusinessObjectUnavailableException) throwable;
            if (log.isWarnEnabled()) {
                log.warn(
                        "Caught an exception during the retrieval of the business objects from the activity from class with name '"
                                + activity.getClass().getName() + "'",
                        exception);
            }
            // We do nothing if the activity is dying
            if (activity != null && activity.isFinishing() == true) {
                return true;
            }
            return exceptionHandler.onBusinessObjectAvailableException(activity, component, exception);
        } else {
            if (log.isWarnEnabled()) {
                log.warn(
                        "Caught an exception during the processing of "
                                + (context == null ? "a null Context"
                                        : "the Context from class with name '" + context.getClass().getName())
                                + "'",
                        throwable);
            }
            // For this special case, we ignore the case when the activity is dying
            if (activity != null) {
                return exceptionHandler.onActivityException(activity, component, throwable);
            } else if (context != null) {
                return exceptionHandler.onContextException(isRecoverable, context, throwable);
            } else {
                return exceptionHandler.onException(isRecoverable, throwable);
            }
        }
    } catch (Throwable otherThrowable) {
        // Just to make sure that handled exceptions do not trigger un-handled exceptions on their turn ;(
        if (log.isErrorEnabled()) {
            log.error(
                    "An error occurred while attempting to handle an exception coming from "
                            + (context == null ? "a null Context"
                                    : "the Context from class with name '" + context.getClass().getName())
                            + "'",
                    otherThrowable);
        }
        return false;
    }
}

From source file:com.juick.android.JuickMessagesAdapter.java

@Override
public boolean isEnabled(int position) {
    Activity context = (Activity) getContext();
    if (context != null && context.isFinishing()) {
        return true;
    }//from  w  ww  .  jav  a2  s  .c o  m
    JuickMessage jmsg = getItem(position);
    boolean retval = jmsg != null && jmsg.User != null && jmsg.getMID() != null;
    return retval;
}