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:tw.com.ksmt.cloud.libs.Utils.java

public static void restartActivity(Context context) {
    Activity activity = (Activity) context;
    Intent intent = activity.getIntent();
    activity.finish();
    activity.startActivity(intent);//from w w  w .  ja  v a 2  s .c o  m
}

From source file:Main.java

public static void restartActivity(Activity activity) {

    if (activity == null)
        return;//  w w w  .ja va  2 s  . c  o  m

    if (Build.VERSION.SDK_INT >= 11) {
        activity.recreate();
    } else {
        Intent intent;
        intent = activity.getIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NO_ANIMATION
                | Intent.FLAG_ACTIVITY_NEW_TASK);
        activity.finish();
        activity.overridePendingTransition(0, 0);
        activity.startActivity(intent);
        activity.overridePendingTransition(0, 0);
    }

}

From source file:Main.java

public static void finishAllActivies(Activity activity) {
    try {/*from   w w w  .ja v  a2s .co m*/
        Class<?> clazz_Activity = Class.forName("android.app.Activity");
        Field field_mMainThread = clazz_Activity.getDeclaredField("mMainThread");
        field_mMainThread.setAccessible(true);
        Object mMainThread = field_mMainThread.get(activity);

        Class<?> clazz_ActivityThread = Class.forName("android.app.ActivityThread");
        Field field_mActivities = clazz_ActivityThread.getDeclaredField("mActivities");
        field_mActivities.setAccessible(true);
        Object mActivities = field_mActivities.get(mMainThread);

        HashMap<?, ?> map = (HashMap<?, ?>) mActivities;
        Collection<?> collections = map.values();
        if (null != collections && !collections.isEmpty()) {
            Class<?> clazz_ActivityClientRecord = Class
                    .forName("android.app.ActivityThread$ActivityClientRecord");
            Field field_activitiy = clazz_ActivityClientRecord.getDeclaredField("activity");
            field_activitiy.setAccessible(true);

            Activity acti;
            for (Object obj : collections) {
                acti = (Activity) field_activitiy.get(obj);
                Log.d(TAG, "activity.name=" + acti.getClass().getName());
                if (null != acti && !acti.isFinishing()) {
                    Log.d(TAG, "activity.name=" + acti.getClass().getName() + " not finish.");
                    acti.finish();
                }
            }
        }
    } catch (NoSuchFieldException e) {
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    } catch (IllegalArgumentException e) {
        e.printStackTrace();
    } catch (ClassNotFoundException e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static AlertDialog createErrorDialog(final Activity activity, String title, String message,
        final boolean doFinish) {
    final AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(message);/*from   w w w.  ja  v  a  2s  . co m*/
    builder.setTitle(title);
    builder.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            if (doFinish) {
                activity.finish();
            }
        }
    });
    return builder.create();
}

From source file:com.arantius.tivocommander.Utils.java

public final static boolean onOptionsItemSelected(MenuItem item, Activity srcActivity, boolean homeIsBack) {
    if (android.R.id.home == item.getItemId() && homeIsBack) {
        srcActivity.finish();
        return true;
    }/*from w  w  w  . j  av a2s.co m*/

    Class<? extends Activity> targetActivity = Utils.activityForMenuId(item.getItemId());
    if (targetActivity == null) {
        Utils.logError("Unknown menu item ID: " + Integer.toString(item.getItemId()));
        return false;
    }
    Intent intent = new Intent(srcActivity, targetActivity);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    srcActivity.startActivity(intent);
    return true;
}

From source file:com.becapps.easydownloader.utils.Utils.java

public static void reload(Activity activity) {
    Intent intent = activity.getIntent();
    intent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    activity.finish();
    activity.overridePendingTransition(0, 0);
    activity.startActivity(intent);//from   ww  w .  j a  v a 2  s.co  m
    activity.overridePendingTransition(0, 0);
}

From source file:Main.java

public static void alertActivityFinish(final Activity activity, String msg) {
    AlertDialog.Builder ad = new AlertDialog.Builder(activity);
    ad.setIcon(activity.getResources().getDrawable(android.R.drawable.ic_dialog_alert)); // Android Resource
    ad.setTitle("Sky Canvas").setMessage(msg).setPositiveButton("OK", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {
            // finish dialog
            dialog.dismiss();/*from  www.j  av  a2  s .co m*/
            activity.finish();
        }
    }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int which) {

        }
    }).show();
    ad = null;
}

From source file:Main.java

public static void alert(final Activity activity, final String msg, final String ok, final boolean exit) {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(msg).setCancelable(false).setPositiveButton(ok, new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.dismiss();/*  w  w  w.j ava  2 s. com*/
            if (exit) {
                activity.setResult(activity.RESULT_CANCELED);
                activity.finish();
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:uk.org.rivernile.android.utils.NavigationUtils.java

/**
 * Call this method when it is necessary to navigate 'up' from an Activity
 * that only has a single known entry point. The parent Activity that is
 * used is defined in the AndroidManifest.xml, as described in 
 * {@link android.support.v4.app.NavUtils}.
 * //from   ww  w . ja  va  2  s  . c  om
 * @param activity The Activity on which 'up' was pressed.
 * @return true if the navigation operation succeeded, false if it didn't.
 * This may happen if activity is null, or the parent Activity was not
 * defined in AndroidManifest.xml.
 * @see android.support.v4.app.NavUtils
 */
public static boolean navigateUpOnActivityWithSingleEntryPoint(final Activity activity) {
    if (activity == null) {
        return false;
    }

    final Intent upIntent = NavUtils.getParentActivityIntent(activity);

    if (upIntent == null) {
        return false;
    }

    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        TaskStackBuilder.create(activity).addNextIntent(upIntent).startActivities();
        activity.finish();
    } else {
        NavUtils.navigateUpTo(activity, upIntent);
    }

    return true;
}

From source file:uk.org.rivernile.android.utils.NavigationUtils.java

/**
 * Call this method when it is necessary to navigate 'up' from an Activity
 * that has multiple entry points. A parent Activity should be defined in
 * AndroidManifest.xml, most likely the home Activity of the application,
 * that will be navigated to if/*  w  w w  .  j a v  a 2s  .  c om*/
 * {@link android.support.v4.app.NavUtils#shouldUpRecreateTask(
 * android.app.Activity, android.content.Intent)} returns true.
 * 
 * @param activity The Activity on which 'up' was pressed.
 * @return true if the navigation operation succeeded, false if it didn't.
 * @see android.support.v4.app.NavUtils
 */
public static boolean navigateUpOnActivityWithMultipleEntryPoints(final Activity activity) {
    if (activity == null) {
        return false;
    }

    final Intent upIntent = NavUtils.getParentActivityIntent(activity);

    if (upIntent == null) {
        return false;
    }

    if (NavUtils.shouldUpRecreateTask(activity, upIntent)) {
        TaskStackBuilder.create(activity).addNextIntent(upIntent).startActivities();
    }

    activity.finish();

    return true;
}