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:Main.java

public static void displayAlert(Context context, String title, String message, String buttonText) {
    if (null == context || !(context instanceof Activity)) {
        return;/*from   ww w  . j a  v  a  2s .  c om*/
    }
    final Activity activity = (Activity) context;

    AlertDialog alertDialog = new AlertDialog.Builder(activity)
            .setPositiveButton(buttonText, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            }).setTitle(title).setMessage(message).create();

    if (!activity.isFinishing()) {
        alertDialog.show();
    }

}

From source file:Main.java

public static void displayAlert4SingleChoice2(final Context context, String title, boolean cancelable,
        String[] selectNames, final DialogInterface.OnClickListener onClickListener) {
    if (null == context || !(context instanceof Activity)) {
        return;// w  ww .java  2 s  .c o m
    }
    final Activity activity = (Activity) context;

    AlertDialog accountDlg = new AlertDialog.Builder(activity).setTitle(title).setCancelable(cancelable)
            .setItems(selectNames, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (null != onClickListener) {
                        onClickListener.onClick(dialog, which);
                    }

                    if (!activity.isFinishing()) {
                        dialog.dismiss();
                    }
                }
            }).create();

    if (!activity.isFinishing()) {
        accountDlg.show();
    }
}

From source file:Main.java

public static void displayAlert4SingleChoice(final Context context, String title, boolean cancelable,
        String[] selectNames, final DialogInterface.OnClickListener onClickListener) {
    if (null == context || !(context instanceof Activity)) {
        return;/*from  ww  w  .  j a  va 2s .co m*/
    }
    final Activity activity = (Activity) context;

    AlertDialog accountDlg = new AlertDialog.Builder(activity).setTitle(title).setCancelable(cancelable)
            .setSingleChoiceItems(selectNames, -1, new OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (null != onClickListener) {
                        onClickListener.onClick(dialog, which);
                    }

                    if (!activity.isFinishing()) {
                        dialog.dismiss();
                    }
                }
            }).create();

    if (!activity.isFinishing()) {
        accountDlg.show();
    }
}

From source file:io.taig.android.mosby.delegate.DialogFragmentMvpDelegateImpl.java

static boolean retainPresenterInstance(Activity activity, Fragment fragment,
        boolean keepPresenterInstanceDuringScreenOrientationChanges, boolean keepPresenterOnBackstack) {

    if (activity.isChangingConfigurations()) {
        return keepPresenterInstanceDuringScreenOrientationChanges;
    }/* www . j av a  2  s.co m*/

    if (activity.isFinishing()) {
        return false;
    }

    if (keepPresenterOnBackstack && BackstackAccessor.isFragmentOnBackStack(fragment)) {
        return true;
    }

    return !fragment.isRemoving();
}

From source file:com.scvngr.levelup.core.test.TestThreadingUtils.java

/**
 * Validates that the Activity becomes finished.
 *
 * @param instrumentation the test {@link Instrumentation}.
 * @param activity the activity to check.
 *//*from   w w  w  .  j  a  va 2s  . com*/
public static void validateActivityFinished(@NonNull final Instrumentation instrumentation,
        @NonNull final Activity activity) {
    final LatchRunnable latchRunnable = new LatchRunnable() {
        @Override
        public void run() {
            if (activity.isFinishing()) {
                countDown();
            }
        }
    };

    AndroidTestCase.assertTrue(waitForAction(instrumentation, activity, latchRunnable, true));
}

From source file:com.github.javiersantos.piracychecker.LibraryUtils.java

static AlertDialog buildUnlicensedDialog(Context context, String title, String content) {
    if (!(context instanceof Activity))
        return null;
    final Activity activity = (Activity) context;
    return new AlertDialog.Builder(context).setCancelable(false).setTitle(title).setMessage(content)
            .setPositiveButton(context.getString(R.string.app_unlicensed_close),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            if (activity.isFinishing())
                                return;
                            activity.finish();
                        }/* w w  w.j a va  2s.  c o  m*/
                    })
            .create();
}

From source file:com.hemou.android.account.AccountUtils.java

/**
 * Get account used for authentication/*from  w  w w . java2 s .c  om*/
 * 
 * @param manager
 * @param act
 * @return account
 * @throws IOException
 * @throws AccountsException
 */
public static Account getAccount(final AccountManager manager, final Activity act)
        throws IOException, AccountsException {
    final String SUB_TAG = "acnt_get";
    final boolean loggable = Log.isLoggable(SUB_TAG, DEBUG);
    if (loggable)
        Log.d(SUB_TAG, "Getting account");

    if (act == null)
        throw new IllegalArgumentException("Activity cannot be null");

    if (act.isFinishing()) {
        Log.v(SUB_TAG, act.getClass().getName()
                + "--->?finish()OperationCanceledException...");
        throw new OperationCanceledException();
    }

    Account[] accounts;
    try {
        if (!hasAuthenticator(manager)) {
            Log.e(SUB_TAG, "Current user is not under the authenticated environment....");
            throw new AuthenticatorConflictException();
        }

        while ((accounts = getAccounts(manager)).length == 0) {
            Bundle result = manager.addAccount(ACCOUNT_TYPE, AUTHTOKEN_TYPE, null, null, act, null, null)
                    .getResult();
        }
    } catch (OperationCanceledException e) {
        Log.d(SUB_TAG, "Excepting retrieving account", e);
        act.finish();
        throw e;
    } catch (AccountsException e) {
        Log.d(SUB_TAG, "Excepting retrieving account", e);
        throw e;
    } catch (AuthenticatorConflictException e) {
        act.runOnUiThread(new Runnable() {

            public void run() {
                showConflictMessage(act);
            }
        });
        throw e;
    } catch (IOException e) {
        Log.d(SUB_TAG, "Excepting retrieving account", e);
        throw e;
    }

    // if (loggable)
    Log.d(SUB_TAG, "Returning account " + accounts[0].name);

    return accounts[0];
}

From source file:jp.co.rediscovery.arflight.ManagerFragment.java

/**
 * ManagerFragment??//from   www  .j  av  a2s .  co m
 * @param activity
 * @return
 */
public static synchronized ManagerFragment getInstance(final Activity activity) {
    ManagerFragment result = null;
    if ((activity != null) && !activity.isFinishing()) {
        final FragmentManager fm = activity.getFragmentManager();
        result = (ManagerFragment) fm.findFragmentByTag(TAG);
        if (result == null) {
            result = new ManagerFragment();
            fm.beginTransaction().add(result, TAG).commit();
        }
    }
    return result;
}

From source file:dentex.youtube.downloader.utils.Utils.java

public static void secureShowDialog(final Activity act, final AlertDialog.Builder adb) {
    act.runOnUiThread(new Runnable() {
        @Override//w  ww . j ava  2 s .  c  o  m
        public void run() {
            if (!act.isFinishing()) {
                adb.show();
            }
        }
    });
}

From source file:com.just.agentweb.AgentWebUtils.java

@Deprecated
static void getUIControllerAndShowMessage(Activity activity, String message, String from) {

    if (activity == null || activity.isFinishing()) {
        return;//from   w  w  w . ja  v a2  s.co m
    }
    WebParentLayout mWebParentLayout = activity.findViewById(R.id.web_parent_layout_id);
    AbsAgentWebUIController mAgentWebUIController = mWebParentLayout.provide();
    if (mAgentWebUIController != null) {
        mAgentWebUIController.onShowMessage(message, from);
    }
}