Example usage for android.app Activity setResult

List of usage examples for android.app Activity setResult

Introduction

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

Prototype

public final void setResult(int resultCode) 

Source Link

Document

Call this to set the result that your activity will return to its caller.

Usage

From source file:org.sufficientlysecure.keychain.ui.linked.LinkedIdCreateGithubFragment.java

@Override
public void onStop() {
    super.onStop();

    if (mFinishOnStop) {
        Activity activity = getActivity();
        activity.setResult(Activity.RESULT_OK);
        activity.finish();/*from  w w  w.  ja  v a  2  s  .  c  om*/
    }
}

From source file:com.granita.tasks.EditTaskFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final int menuId = item.getItemId();
    Activity activity = getActivity();
    if (menuId == R.id.editor_action_save) {
        saveAndExit();//w w  w .j  a  va  2s  .  c  o  m
        return true;
    } else if (menuId == R.id.editor_action_cancel) {
        activity.setResult(Activity.RESULT_CANCELED);
        activity.finish();
        return true;
    }
    return false;
}

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();/*  w  ww  .j  a  va2 s .c  om*/
        } else {
            // 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:org.akvo.caddisfly.ui.ExternalActionActivity.java

/**
 * Alert message for calibration incomplete or invalid.
 *///from w  w w .  j  ava2s  .c  om
private void alertCalibrationIncomplete() {

    final Activity activity = this;

    String message = getString(R.string.errorCalibrationIncomplete,
            CaddisflyApp.getApp().getCurrentTestInfo().getName());
    message = String.format(MESSAGE_TWO_LINE_FORMAT, message, getString(R.string.doYouWantToCalibrate));

    AlertUtil.showAlert(this, R.string.cannotStartTest, message, R.string.calibrate,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    final Intent intent = new Intent(getBaseContext(), CalibrateListActivity.class);
                    startActivity(intent);

                    activity.setResult(Activity.RESULT_CANCELED);
                    dialogInterface.dismiss();
                    finish();
                }
            }, new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    activity.setResult(Activity.RESULT_CANCELED);
                    dialogInterface.dismiss();
                    finish();
                }
            }, new DialogInterface.OnCancelListener() {
                @Override
                public void onCancel(DialogInterface dialogInterface) {
                    activity.setResult(Activity.RESULT_CANCELED);
                    dialogInterface.dismiss();
                    finish();
                }
            });
}

From source file:org.totschnig.myexpenses.activity.CommonCommands.java

static boolean dispatchCommand(Activity ctx, int command, Object tag) {
    Intent i;/*from  w  w w.ja v a  2s  .c o  m*/
    switch (command) {
    case R.id.RATE_COMMAND:
        i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(MyApplication.getMarketSelfUri()));
        if (Utils.isIntentAvailable(ctx, i)) {
            ctx.startActivity(i);
        } else {
            Toast.makeText(ctx, R.string.error_accessing_market, Toast.LENGTH_LONG).show();
        }
        return true;
    case R.id.SETTINGS_COMMAND:
        i = new Intent(ctx, MyPreferenceActivity.class);
        i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        if (tag != null) {
            i.putExtra(MyPreferenceActivity.KEY_OPEN_PREF_KEY, (String) tag);
        }
        ctx.startActivityForResult(i, ProtectedFragmentActivity.PREFERENCES_REQUEST);
        return true;
    case R.id.FEEDBACK_COMMAND:
        i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("plain/text");
        i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { MyApplication.FEEDBACK_EMAIL });
        i.putExtra(android.content.Intent.EXTRA_SUBJECT, "[" + ctx.getString(R.string.app_name) + "] Feedback");
        i.putExtra(android.content.Intent.EXTRA_TEXT,
                getVersionInfo(ctx) + "\n" + ctx.getString(R.string.feedback_email_message));
        if (!Utils.isIntentAvailable(ctx, i)) {
            Toast.makeText(ctx, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show();
        } else {
            ctx.startActivity(i);
        }
        break;
    case R.id.CONTRIB_INFO_COMMAND:
        CommonCommands.showContribInfoDialog((FragmentActivity) ctx, -1);
        return true;
    case R.id.WEB_COMMAND:
        i = new Intent(Intent.ACTION_VIEW);
        i.setData(Uri.parse(ctx.getString(R.string.website)));
        ctx.startActivity(i);
        return true;
    case R.id.HELP_COMMAND:
        i = new Intent(ctx, Help.class);
        i.putExtra(HelpDialogFragment.KEY_VARIANT,
                tag != null ? (Enum<?>) tag : ((ProtectedFragmentActivity) ctx).helpVariant);
        //for result is needed since it allows us to inspect the calling activity
        ctx.startActivityForResult(i, 0);
        return true;
    case R.id.REQUEST_LICENCE_COMMAND:
        String androidId = Settings.Secure.getString(ctx.getContentResolver(), Settings.Secure.ANDROID_ID);
        i = new Intent(android.content.Intent.ACTION_SEND);
        i.setType("plain/text");
        i.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { MyApplication.FEEDBACK_EMAIL });
        i.putExtra(android.content.Intent.EXTRA_SUBJECT,
                "[" + ctx.getString(R.string.app_name) + "] " + ctx.getString(R.string.contrib_key));
        String extraText = ctx.getString(R.string.request_licence_mail_head, androidId);
        if (tag != null) {
            extraText += " \n\n[" + ctx.getString(R.string.paypal_transaction_id) + ": " + tag + "]";
        }
        i.putExtra(android.content.Intent.EXTRA_TEXT, extraText);
        if (!Utils.isIntentAvailable(ctx, i)) {
            Toast.makeText(ctx, R.string.no_app_handling_email_available, Toast.LENGTH_LONG).show();
        } else {
            ctx.startActivity(i);
        }
        return true;
    case R.id.VERIFY_LICENCE_COMMAND:
        HashLicenceHandler licenceHandler = (HashLicenceHandler) MyApplication.getInstance()
                .getLicenceHandler();
        LicenceHandler.LicenceStatus licenceStatus = licenceHandler.verifyLicenceKey();
        if (licenceStatus != null) {
            Toast.makeText(ctx,
                    Utils.concatResStrings(ctx, " ", R.string.licence_validation_success,
                            (licenceStatus == LicenceHandler.LicenceStatus.EXTENDED
                                    ? R.string.licence_validation_extended
                                    : R.string.licence_validation_premium)),
                    Toast.LENGTH_LONG).show();
        } else {
            Toast.makeText(ctx, R.string.licence_validation_failure, Toast.LENGTH_LONG).show();
        }
        licenceHandler.invalidate();
        return true;
    case android.R.id.home:
        ctx.setResult(FragmentActivity.RESULT_CANCELED);
        ctx.finish();
        return true;
    }
    return false;
}