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:io.github.mkjung.ivi.util.Permissions.java

private static Dialog createDialog(final Activity activity, boolean exit) {
    android.app.AlertDialog.Builder dialogBuilder = new android.app.AlertDialog.Builder(activity)
            .setTitle(activity.getString(R.string.allow_storage_access_title))
            .setMessage(activity.getString(R.string.allow_storage_access_description))
            .setIcon(android.R.drawable.ic_dialog_alert).setPositiveButton(
                    activity.getString(R.string.permission_ask_again), new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int whichButton) {
                            SharedPreferences settings = PreferenceManager
                                    .getDefaultSharedPreferences(activity);
                            if (!settings.getBoolean("user_declined_storage_access", false))
                                requestStoragePermission(activity);
                            else {
                                Intent i = new Intent();
                                i.setAction("android.settings.APPLICATION_DETAILS_SETTINGS");
                                i.addCategory(Intent.CATEGORY_DEFAULT);
                                i.setData(Uri
                                        .parse("package:" + VLCApplication.getAppContext().getPackageName()));
                                i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                                try {
                                    activity.startActivity(i);
                                } catch (Exception ex) {
                                }/*w  w  w. j a v  a  2s.c o  m*/
                            }
                            SharedPreferences.Editor editor = settings.edit();
                            editor.putBoolean("user_declined_storage_access", true);
                            Util.commitPreferences(editor);
                        }
                    });
    if (exit) {
        dialogBuilder.setNegativeButton(activity.getString(R.string.exit_app),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.finish();
                    }
                }).setCancelable(false);
    }
    return dialogBuilder.show();
}

From source file:com.vuze.android.remote.AndroidUtils.java

public static void showConnectionError(final Activity activity, final String errMsg,
        final boolean allowContinue) {
    if (AndroidUtils.DEBUG) {
        Log.d(TAG, "showConnectionError.string " + AndroidUtils.getCompressedStackTrace());
    }/*from w w  w . j a v a  2 s .c o m*/
    if (activity == null) {
        Log.e(null, "No activity for error message " + errMsg);
        return;
    }
    activity.runOnUiThread(new Runnable() {
        public void run() {
            if (activity.isFinishing()) {
                if (DEBUG) {
                    System.out.println("can't display -- finishing");
                }
                return;
            }
            Builder builder = new AlertDialog.Builder(activity).setTitle(R.string.error_connecting)
                    .setMessage(errMsg).setCancelable(true)
                    .setNegativeButton(R.string.action_logout, new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            if (activity.isTaskRoot()) {
                                RemoteUtils.openRemoteList(activity);
                            }
                            activity.finish();
                        }
                    });
            if (allowContinue) {
                builder.setPositiveButton(R.string.button_continue, new OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    }
                });
            }
            AndroidUtils.openSingleAlertDialog(activity, builder);
        }
    });

}

From source file:com.gigigo.vuforia.core.sdkimagerecognition.cloudrecognition.CloudRecognition.java

public void showErrorMessage(int errorCode, double errorTime, boolean finishActivityOnError) {
    //you can change for show or hidden the vuforia error messages
    if (bShowErrorMessages) {
        if (errorTime < (mLastErrorTime + 5.0) || errorCode == mlastErrorCode)
            return;

        mlastErrorCode = errorCode;//from w ww  . ja  v a  2  s  .c o m
        mFinishActivityOnError = finishActivityOnError;

        final Activity activity = this.mActivity;

        this.mActivity.runOnUiThread(new Runnable() {
            public void run() {
                if (mErrorDialog != null) {
                    mErrorDialog.dismiss();
                }

                // Generates an Alert Dialog to show the error message
                AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                builder.setMessage(getStatusDescString(CloudRecognition.this.mlastErrorCode))
                        .setTitle(getStatusTitleString(CloudRecognition.this.mlastErrorCode))
                        .setCancelable(false).setIcon(0).setPositiveButton(
                                activity.getString(R.string.button_OK), new DialogInterface.OnClickListener() {
                                    public void onClick(DialogInterface dialog, int id) {
                                        if (mFinishActivityOnError) {
                                            activity.finish();
                                        } else {
                                            dialog.dismiss();
                                        }
                                    }
                                });

                mErrorDialog = builder.create();
                mErrorDialog.show();
            }
        });
    }
}

From source file:com.soomla.store.billing.nokia.NokiaIabHelper.java

/**
 * See parent/*from  w ww .  j  a  va2 s.co m*/
 */
@Override
protected void launchPurchaseFlowInner(Activity act, String sku, String extraData) {
    IabResult result;

    try {
        SoomlaUtils.LogDebug(TAG, "Constructing buy intent for " + sku + ", item type: " + ITEM_TYPE_INAPP);
        Bundle buyIntentBundle = mService.getBuyIntent(3, SoomlaApp.getAppContext().getPackageName(), sku,
                ITEM_TYPE_INAPP, extraData);
        buyIntentBundle.putString("PURCHASE_SKU", sku);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
            SoomlaUtils.LogError(TAG,
                    "Unable to buy item, Error response: " + IabResult.getResponseDesc(response));

            IabPurchase failPurchase = new IabPurchase(ITEM_TYPE_INAPP, "{\"productId\":" + sku + "}", "");
            result = new IabResult(response, "Unable to buy item");
            purchaseFailed(result, failPurchase);
            act.finish();
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        SoomlaUtils.LogDebug(TAG, "Launching buy intent for " + sku + ". Request code: " + RC_REQUEST);
        mPurchasingItemSku = sku;
        mPurchasingItemType = ITEM_TYPE_INAPP;

        act.startIntentSenderForResult(pendingIntent.getIntentSender(), RC_REQUEST, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        SoomlaUtils.LogError(TAG, "SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        purchaseFailed(result, null);
    } catch (RemoteException e) {
        SoomlaUtils.LogError(TAG, "RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                "Remote exception while starting purchase flow");
        purchaseFailed(result, null);
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "Failed to generate failing purchase.");
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate failing purchase.");
        purchaseFailed(result, null);
    }

}

From source file:im.vector.VectorApp.java

/**
 * Restart an activity to manage language update
 *
 * @param activity the activity to restart
 *//*from   w ww. j av  a 2  s.c  om*/
private void restartActivity(Activity activity) {
    // avoid restarting activities when it is not required
    // some of them has no text
    if (!(activity instanceof VectorMediasPickerActivity) && !(activity instanceof VectorCallViewActivity)
            && !(activity instanceof JitsiCallActivity) && !(activity instanceof WidgetActivity)) {
        activity.startActivity(activity.getIntent());
        activity.finish();
    }
}

From source file:com.soomla.store.billing.google.GoogleIabHelper.java

/**
 * See parent//from  w ww. j a v a  2  s. c  om
 */
@Override
protected void launchPurchaseFlowInner(Activity act, String sku, String extraData) {
    IabResult result;

    try {
        SoomlaUtils.LogDebug(TAG, "Constructing buy intent for " + sku + ", item type: " + ITEM_TYPE_INAPP);
        Bundle buyIntentBundle = mService.getBuyIntent(3, SoomlaApp.getAppContext().getPackageName(), sku,
                ITEM_TYPE_INAPP, extraData);
        buyIntentBundle.putString("PURCHASE_SKU", sku);
        int response = getResponseCodeFromBundle(buyIntentBundle);
        if (response != IabResult.BILLING_RESPONSE_RESULT_OK) {
            SoomlaUtils.LogError(TAG,
                    "Unable to buy item, Error response: " + IabResult.getResponseDesc(response));

            IabPurchase failPurchase = new IabPurchase(ITEM_TYPE_INAPP, "{\"productId\":" + sku + "}", null);
            result = new IabResult(response, "Unable to buy item");
            purchaseFailed(result, failPurchase);
            act.finish();
            return;
        }

        PendingIntent pendingIntent = buyIntentBundle.getParcelable(RESPONSE_BUY_INTENT);
        SoomlaUtils.LogDebug(TAG, "Launching buy intent for " + sku + ". Request code: " + RC_REQUEST);
        mPurchasingItemSku = sku;
        mPurchasingItemType = ITEM_TYPE_INAPP;

        act.startIntentSenderForResult(pendingIntent.getIntentSender(), RC_REQUEST, new Intent(),
                Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(0));
    } catch (SendIntentException e) {
        SoomlaUtils.LogError(TAG, "SendIntentException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_SEND_INTENT_FAILED, "Failed to send intent.");
        purchaseFailed(result, null);
    } catch (RemoteException e) {
        SoomlaUtils.LogError(TAG, "RemoteException while launching purchase flow for sku " + sku);
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_REMOTE_EXCEPTION,
                "Remote exception while starting purchase flow");
        purchaseFailed(result, null);
    } catch (JSONException e) {
        SoomlaUtils.LogError(TAG, "Failed to generate failing purchase.");
        e.printStackTrace();

        result = new IabResult(IabResult.IABHELPER_BAD_RESPONSE, "Failed to generate failing purchase.");
        purchaseFailed(result, null);
    }

}

From source file:de.spiritcroc.ownlog.ui.fragment.ImportLogFragment.java

private void loadImportDb(String passwd) {
    if (mDbHelper == null) {
        mDbHelper = new ExternalDbReadHelper(mImportFiles.logDbFile.getAbsolutePath());
    }//from  w w w.ja  va 2s . c o m
    SQLiteDatabase db = null;
    try {
        db = mDbHelper.getReadableDatabase(passwd);
    } catch (SQLiteException e) {
        e.printStackTrace();
    } catch (DbHelper.UnsupportedUpgradeException e) {
        Log.w(TAG, "Import: unsupported upgrade from " + e.oldVersion);
        // Unsupported db version: notify user and close activity
        invalidImport();
        // No more prompting for password
        return;
    }
    if (db != null) {
        new LoadBackupTask(db).execute();
    } else {
        // Prompt for password
        final Activity activity = getActivity();
        AlertDialog.Builder builder = new AlertDialog.Builder(activity);
        final View view = activity.getLayoutInflater().inflate(R.layout.dialog_request_password, null);

        final EditText editPassword = (EditText) view.findViewById(R.id.edit_password);

        final AlertDialog alertDialog = builder.setTitle(R.string.import_dialog_request_password).setView(view)
                .setCancelable(false)
                .setPositiveButton(R.string.dialog_ok, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        loadImportDb(editPassword.getText().toString());
                    }
                }).setNegativeButton(R.string.dialog_cancel, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        activity.finish();
                        mDbHelper.close();
                    }
                }).show();

        // Edit text requires user interaction, so show keyboard
        alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }
}

From source file:im.neon.activity.CommonActivityUtils.java

/**
 * With android M, the permissions kills the backgrounded application
 * and try to restart the last opened activity.
 * But, the sessions are not initialised (i.e the stores are not ready and so on).
 * Thus, the activity could have an invalid behaviour.
 * It seems safer to go to splash screen and to wait for the end of the initialisation.
 *
 * @param activity  the caller activity//  ww  w .j a va  2s .c om
 * @param sessionId the session id
 * @param roomId    the room id
 * @return true if go to splash screen
 */
public static boolean isGoingToSplash(Activity activity, String sessionId, String roomId) {
    if (Matrix.hasValidSessions()) {
        List<MXSession> sessions = Matrix.getInstance(activity).getSessions();

        for (MXSession session : sessions) {
            if (session.isAlive() && !session.getDataHandler().getStore().isReady()) {
                Intent intent = new Intent(activity, SplashActivity.class);

                if ((null != sessionId) && (null != roomId)) {
                    intent.putExtra(SplashActivity.EXTRA_MATRIX_ID, sessionId);
                    intent.putExtra(SplashActivity.EXTRA_ROOM_ID, roomId);
                }

                activity.startActivity(intent);
                activity.finish();
                return true;
            }
        }
    }

    return false;
}

From source file:com.ringdroid.RingdroidEditActivity.java

private void onSave() {
    if (mIsPlaying) {
        handlePause();//from w  w  w . j a  v  a 2 s . co m
    }

    final Activity activity = this;
    final Handler finishHandler = new Handler() {
        public void handleMessage(Message response) {
            activity.finish();
        }
    };
    final Handler handler = new Handler() {
        public void handleMessage(Message response) {
            CharSequence newTitle = (CharSequence) response.obj;
            mNewFileKind = response.arg1;
            saveRingtone(newTitle);
        }
    };
    Message message = Message.obtain(handler);
    FileSaveDialog dlog = new FileSaveDialog(this, getResources(), Utils.convertGBK(mTitle), message);
    dlog.show();
}