Example usage for android.app Activity finish

List of usage examples for android.app Activity finish

Introduction

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

Prototype

public void finish() 

Source Link

Document

Call this when your activity is done and should be closed.

Usage

From source file:Main.java

public static String getResourceString(String paramString, Activity paramActivity) {
    Class localClass = null;//from  www.ja v a 2 s  .c om
    if (0 == 0)
        ;
    try {
        localClass = Class.forName(paramActivity.getPackageName() + ".R$string");
        String str = paramActivity.getResources()
                .getString(((Integer) localClass.getDeclaredField(paramString).get(null)).intValue());
        return str;
    } catch (Exception localException) {
        Log.e(paramActivity.getPackageName(), localException.getMessage(), localException);
        paramActivity.finish();
    }
    return "";
}

From source file:Main.java

public static String getResourceString(String recourceName, Activity context) {
    Class rStringClass = null;//from  w  ww.  j  ava 2 s  .c  o  m
    try {
        if (rStringClass == null) {
            rStringClass = Class.forName(
                    new StringBuilder().append(context.getPackageName()).append(".R$string").toString());
        }
        return context.getResources()
                .getString(((Integer) rStringClass.getDeclaredField(recourceName).get(null)).intValue());
    } catch (Exception e) {
        Log.e(context.getPackageName(), e.getMessage(), e);
        context.finish();
    }
    return "";
}

From source file:de.k3b.android.toGoZip.PermissionHelper.java

/**
 * called in onRequestPermissionsResult().
 *
 * @return true if just received permissions. else false and calling finish
 *//*ww  w .j  a  v  a2 s  .c  om*/
public static boolean receivedPermissionsOrFinish(Activity activity, int requestCode,
        @NonNull String[] permissions, @NonNull int[] grantResults) {
    if (requestCode == REQUEST_CODE_STORAGE) {
        if ((grantResults.length == 2) && (grantResults[0] == PackageManager.PERMISSION_GRANTED)
                && (grantResults[1] == PackageManager.PERMISSION_GRANTED)) {
            return true;
        } else {
            showNowPermissionMessage(activity);
            activity.finish();
        }
    }
    return false;
}

From source file:com.nextgis.mobile.fragment.SettingsFragment.java

public static void initializeTheme(final Activity activity, final ListPreference theme) {
    if (null != theme) {
        theme.setSummary(theme.getEntry());

        theme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override// w w w.  ja  va  2 s  .  c o  m
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                activity.startActivity(activity.getIntent());
                activity.finish();
                return true;
            }
        });
    }
}

From source file:org.akvo.caddisfly.util.ApiUtil.java

public static boolean isCameraInUse(Context context, @Nullable final Activity activity) {
    Camera camera = null;/*  w w w.  jav  a 2  s. c  o  m*/
    try {
        camera = CameraHelper.getCamera(context, new DialogInterface.OnClickListener() {
            @Override
            public void onClick(@NonNull DialogInterface dialogInterface, int i) {
                dialogInterface.dismiss();
                if (activity != null) {
                    activity.finish();
                }
            }
        });

    } catch (Exception ignored) {
    }

    if (camera != null) {
        camera.release();
        return false;
    }

    return true;
}

From source file:com.nextgis.mobile.util.ApkDownloader.java

public static void check(final Activity activity, final boolean showToast) {
    final String token = PreferenceManager.getDefaultSharedPreferences(activity)
            .getString(NGIDUtils.PREF_ACCESS_TOKEN, "");
    if (showToast && TextUtils.isEmpty(token)) {
        Toast.makeText(activity, R.string.error_401, Toast.LENGTH_SHORT).show();
        activity.finish();
        return;//from ww w  . java 2 s.c om
    }

    NGIDUtils.get(activity, SettingsConstants.APK_VERSION_UPDATE, new NGIDUtils.OnFinish() {
        @Override
        public void onFinish(String data) {
            if (data != null) {
                try {
                    JSONObject json = new JSONObject(data);
                    if (json.getInt("versionCode") <= BuildConfig.VERSION_CODE) {
                        if (showToast) {
                            Toast.makeText(activity, R.string.update_no, Toast.LENGTH_SHORT).show();
                            activity.finish();
                        }
                        return;
                    }

                    // there is new version, create download dialog
                    final String url = json.getString("path");
                    DialogInterface.OnClickListener dcl = new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int button) {
                            if (button == DialogInterface.BUTTON_POSITIVE)
                                new ApkDownloader(activity, showToast).execute(url, token);
                            else if (showToast)
                                activity.finish();
                        }
                    };

                    AlertDialog.Builder adb = new AlertDialog.Builder(activity);
                    String update = String.format(activity.getString(R.string.update_new),
                            json.getString("versionName"));
                    adb.setMessage(update).setTitle(R.string.update_title).setPositiveButton(R.string.yes, dcl)
                            .setNegativeButton(R.string.no, dcl).show();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        }
    });
}

From source file:com.amaze.carbonfilemanager.fragments.preference_fragments.Preffrag.java

public static void restartPC(final Activity activity) {
    if (activity == null)
        return;/* w ww  . ja va  2 s.  c om*/

    final int enter_anim = android.R.anim.fade_in;
    final int exit_anim = android.R.anim.fade_out;
    activity.overridePendingTransition(enter_anim, exit_anim);
    activity.finish();
    activity.overridePendingTransition(enter_anim, exit_anim);
    activity.startActivity(activity.getIntent());
}

From source file:org.chromium.chrome.browser.firstrun.FirstRunActivity.java

private static void finishAllFREActivities(int result, Intent data) {
    List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> weakActivity : activities) {
        Activity activity = weakActivity.get();
        if (activity instanceof FirstRunActivity) {
            activity.setResult(result, data);
            activity.finish();
        }/*ww  w  .ja  va  2 s  .  c om*/
    }
}

From source file:com.android.contacts.common.activity.RequestPermissionsActivityBase.java

/**
 * If any permissions the Contacts app needs are missing, open an Activity
 * to prompt the user for these permissions. Moreover, finish the current activity.
 *
 * This is designed to be called inside {@link android.app.Activity#onCreate}
 *//* w w  w. ja  va 2s  . c  o  m*/
protected static boolean startPermissionActivity(Activity activity, String[] requiredPermissions,
        Class<?> newActivityClass) {
    if (!hasPermissions(activity, requiredPermissions)) {
        final Intent intent = new Intent(activity, newActivityClass);
        activity.getIntent().putExtra(STARTED_PERMISSIONS_ACTIVITY, true);
        intent.putExtra(PREVIOUS_ACTIVITY_INTENT, activity.getIntent());
        activity.startActivity(intent);
        activity.finish();
        return true;
    }

    // Account type initialization must be delayed until the Contacts permission group
    // has been granted (since GET_ACCOUNTS) falls under that groups.  Previously it
    // was initialized in ContactApplication which would cause problems as
    // AccountManager.getAccounts would return an empty array. See b/22690336
    AccountTypeManager.getInstance(activity);

    return false;
}

From source file:com.todoroo.astrid.activity.AddOnActivity.java

/**
 * Creates an on click listener/* w  w  w. j av a 2  s  .c  o m*/
 * @param activity
 * @param finish whether to finish activity
 * @return
 */
public static DialogInterface.OnClickListener createAddOnClicker(final Activity activity,
        final boolean finish) {
    return new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Intent intent = new Intent(activity, AddOnActivity.class);
            intent.putExtra(AddOnActivity.TOKEN_START_WITH_AVAILABLE, true);
            activity.startActivity(intent);
            if (finish)
                activity.finish();
        }
    };
}