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:org.odk.collect.android.fragments.Camera2VideoFragment.java

private void stopRecordingVideo() {
    // UI/*  ww w. j ava2s.c o m*/
    isRecordingVideo = false;
    // Stop recording
    mediaRecorder.stop();
    mediaRecorder.reset();

    Activity activity = getActivity();
    if (null != activity) {
        Timber.d("Video saved: " + nextVideoAbsolutePath);
    }
    Intent i = new Intent();
    i.setData(Uri.fromFile(new File(nextVideoAbsolutePath)));
    activity.setResult(Activity.RESULT_OK, i);
    activity.finish();
}

From source file:org.getlantern.firetweet.fragment.support.AccountsDashboardFragment.java

private void closeActivity() {
    final Activity activity = getActivity();
    if (activity instanceof HomeActivity) {
        ((HomeActivity) activity).closeAccountsDrawer();
    }/* w  w w  . j av  a2  s . co  m*/
    activity.finish();
}

From source file:org.csware.ee.utils.Tools.java

public static void show(final Activity activity, final int id) {
    final Context context = activity;
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle("");
    builder.setMessage("");

    builder.setPositiveButton("", new DialogInterface.OnClickListener() {
        @Override//from w w w . j a  va 2 s  . co  m
        public void onClick(DialogInterface dialog, int which) {
            int version = android.os.Build.VERSION.SDK_INT;
            Intent intent;
            if (version < 11) {
                intent = new Intent();
                intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings");
            } else {
                //3.0?
                //intent = new Intent( android.provider.Settings.ACTION_WIRELESS_SETTINGS);
                intent = new Intent(android.provider.Settings.ACTION_SETTINGS);
            }
            if (id == 1) {
                activity.finish();
            }
            context.startActivity(intent);
        }
    });
    builder.setNegativeButton("?", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (id == 1) {
                activity.finish();
            }
        }
    });
    builder.create().show();
}

From source file:com.afwsamples.testdpc.SetupManagementFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    Activity activity = getActivity();

    switch (requestCode) {
    case REQUEST_PROVISION_MANAGED_PROFILE:
    case REQUEST_PROVISION_DEVICE_OWNER:
        if (resultCode == Activity.RESULT_OK) {
            // Success, finish the enclosing activity. NOTE: Only finish once we're done
            // here, as in synchronous auth cases we don't want the user to return to the
            // Android setup wizard or add-account flow prematurely.
            activity.setResult(Activity.RESULT_OK);
            activity.finish();
        } else {//  ww  w .  j ava  2 s  .  com
            // Something went wrong (either provisioning failed, or the user backed out).
            // Let the user decide how to proceed.
            Toast.makeText(activity, R.string.provisioning_failed_or_cancelled, Toast.LENGTH_SHORT).show();
        }
        break;
    case REQUEST_GET_LOGO:
        if (data != null && data.getData() != null) {
            mLogoUri = data.getData();
            mLogoValue.setText(mLogoUri.getLastPathSegment());
            Util.updateImageView(getActivity(), mLogoPreviewView, mLogoUri);
        }
        break;
    }
}

From source file:com.ultramegasoft.flavordex2.fragment.EditCatFragment.java

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (resultCode == Activity.RESULT_OK) {
        switch (requestCode) {
        case REQUEST_DELETE_CAT:
            final Activity activity = getActivity();
            if (activity != null) {
                activity.finish();
            }/*from  ww  w .  j a va2 s. c o m*/
            break;
        }
    }
}

From source file:org.matrix.console.activity.CommonActivityUtils.java

/**
 * Logout the current user./*from   w  ww.j  av a2s .co m*/
 * @param activity the caller activity
 */
public static void logout(Activity activity) {
    stopEventStream(activity);

    try {
        ShortcutBadger.setBadge(activity, 0);
    } catch (Exception e) {
    }

    // warn that the user logs out
    Collection<MXSession> sessions = Matrix.getMXSessions(activity);
    for (MXSession session : sessions) {
        // Publish to the server that we're now offline
        MyPresenceManager.getInstance(activity, session).advertiseOffline();
        MyPresenceManager.remove(session);
    }

    // clear the preferences
    PreferenceManager.getDefaultSharedPreferences(activity).edit().clear().commit();

    // reset the GCM
    Matrix.getInstance(activity).getSharedGcmRegistrationManager().reset();

    // clear credentials
    Matrix.getInstance(activity).clearSessions(activity, true);

    // ensure that corrupted values are cleared
    Matrix.getInstance(activity).getLoginStorage().clear();

    // reset the contacts
    PIDsRetriever.getIntance().reset();
    ContactsManager.reset();

    MXMediasCache.clearThumbnailsCache(activity);

    // go to login page
    activity.startActivity(new Intent(activity, LoginActivity.class));
    activity.finish();
}

From source file:org.sufficientlysecure.keychain.ui.token.ManageSecurityTokenFragment.java

@Override
public void finishAndShowKey(long masterKeyId) {
    Activity activity = getActivity();

    Intent viewKeyIntent = new Intent(activity, ViewKeyActivity.class);
    // use the imported masterKeyId, not the one from the token, because
    // that one might* just have been a subkey of the imported key
    viewKeyIntent.setData(KeyRings.buildGenericKeyRingUri(masterKeyId));

    if (activity instanceof CreateKeyActivity) {
        ((CreateKeyActivity) activity).finishWithFirstTimeHandling(viewKeyIntent);
    } else {/* ww  w  .  j av a 2  s.  c om*/
        activity.startActivity(viewKeyIntent);
        activity.finish();
    }
}

From source file:org.openremote.android.console.GroupActivity.java

/**
 * If the controller refreshed, finish this activity.
 *//*from  w  w  w . j  a v  a  2 s.co  m*/
private void addControllerRefreshEventListener() {
    final Activity that = this;
    ORListenerManager.getInstance().addOREventListener(ListenerConstant.FINISH_GROUP_ACTIVITY,
            new OREventListener() {
                @Override
                public void handleEvent(OREvent event) {
                    that.finish();
                }
            });
}

From source file:com.xandy.calendar.event.EditEventFragment.java

protected void displayEditWhichDialog() {
    if (mModification == Utils.MODIFY_UNINITIALIZED) {
        final boolean notSynced = TextUtils.isEmpty(mModel.mSyncId);
        boolean isFirstEventInSeries = mModel.mIsFirstEventInSeries;
        int itemIndex = 0;
        CharSequence[] items;/*from ww w . j  a v  a  2 s.c  o  m*/

        if (notSynced) {
            // If this event has not been synced, then don't allow deleting
            // or changing a single instance.
            if (isFirstEventInSeries) {
                // Still display the option so the user knows all events are
                // changing
                items = new CharSequence[1];
            } else {
                items = new CharSequence[2];
            }
        } else {
            if (isFirstEventInSeries) {
                items = new CharSequence[2];
            } else {
                items = new CharSequence[3];
            }
            items[itemIndex++] = mActivity.getText(R.string.modify_event);
        }
        items[itemIndex++] = mActivity.getText(R.string.modify_all);

        // Do one more check to make sure this remains at the end of the list
        if (!isFirstEventInSeries) {
            items[itemIndex++] = mActivity.getText(R.string.modify_all_following);
        }

        // Display the modification dialog.
        if (mModifyDialog != null) {
            mModifyDialog.dismiss();
            mModifyDialog = null;
        }
        mModifyDialog = new AlertDialog.Builder(mActivity).setTitle(R.string.edit_event_label)
                .setItems(items, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            // Update this if we start allowing exceptions
                            // to unsynced events in the app
                            mModification = notSynced ? Utils.MODIFY_ALL : Utils.MODIFY_SELECTED;
                            if (mModification == Utils.MODIFY_SELECTED) {
                                mModel.mOriginalSyncId = notSynced ? null : mModel.mSyncId;
                                mModel.mOriginalId = mModel.mId;
                            }
                        } else if (which == 1) {
                            mModification = notSynced ? Utils.MODIFY_ALL_FOLLOWING : Utils.MODIFY_ALL;
                        } else if (which == 2) {
                            mModification = Utils.MODIFY_ALL_FOLLOWING;
                        }

                        mView.setModification(mModification);
                    }
                }).show();

        mModifyDialog.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                Activity a = EditEventFragment.this.getActivity();
                if (a != null) {
                    a.finish();
                }
            }
        });
    }
}

From source file:com.android.calendar.event.EditEventFragment.java

protected void displayEditWhichDialog() {
    if (mModification == Utils.MODIFY_UNINITIALIZED) {
        final boolean notSynced = TextUtils.isEmpty(mModel.mSyncId);
        boolean isFirstEventInSeries = mModel.mIsFirstEventInSeries;
        int itemIndex = 0;
        CharSequence[] items;/*from  ww  w .j a  v  a  2  s.  co  m*/

        if (notSynced) {
            // If this event has not been synced, then don't allow deleting
            // or changing a single instance.
            if (isFirstEventInSeries) {
                // Still display the option so the user knows all events are
                // changing
                items = new CharSequence[1];
            } else {
                items = new CharSequence[2];
            }
        } else {
            if (isFirstEventInSeries) {
                items = new CharSequence[2];
            } else {
                items = new CharSequence[3];
            }
            items[itemIndex++] = mContext.getText(R.string.modify_event);
        }
        items[itemIndex++] = mContext.getText(R.string.modify_all);

        // Do one more check to make sure this remains at the end of the list
        if (!isFirstEventInSeries) {
            items[itemIndex++] = mContext.getText(R.string.modify_all_following);
        }

        // Display the modification dialog.
        if (mModifyDialog != null) {
            mModifyDialog.dismiss();
            mModifyDialog = null;
        }
        mModifyDialog = new AlertDialog.Builder(mContext).setTitle(R.string.edit_event_label)
                .setItems(items, new OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        if (which == 0) {
                            // Update this if we start allowing exceptions
                            // to unsynced events in the app
                            mModification = notSynced ? Utils.MODIFY_ALL : Utils.MODIFY_SELECTED;
                            if (mModification == Utils.MODIFY_SELECTED) {
                                mModel.mOriginalSyncId = notSynced ? null : mModel.mSyncId;
                                mModel.mOriginalId = mModel.mId;
                            }
                        } else if (which == 1) {
                            mModification = notSynced ? Utils.MODIFY_ALL_FOLLOWING : Utils.MODIFY_ALL;
                        } else if (which == 2) {
                            mModification = Utils.MODIFY_ALL_FOLLOWING;
                        }

                        mView.setModification(mModification);
                    }
                }).show();

        mModifyDialog.setOnCancelListener(new OnCancelListener() {
            @Override
            public void onCancel(DialogInterface dialog) {
                Activity a = EditEventFragment.this.getActivity();
                if (a != null) {
                    a.finish();
                }
            }
        });
    }
}