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:Main.java

public static void returnControlToCallingActivity(Activity activity) {
    activity.setResult(activity.getIntent().getIntExtra("requestCode", 0));
    activity.finish();//from w w  w. ja v  a  2  s . c om
}

From source file:Main.java

public static void finishWithResultCode(Activity context, int resultCode) {
    Activity parentActivity = context.getParent();
    context.setResult(resultCode);
    context.finish();/*  w  ww  .  j  a v  a 2  s . c  o  m*/
    if (parentActivity != null) {
        parentActivity.overridePendingTransition(0, android.R.anim.slide_out_right);
    } else {
        context.overridePendingTransition(0, android.R.anim.slide_out_right);
    }
}

From source file:Main.java

public static void resultSetParameter(Activity context, int resultCode) {
    context.setResult(resultCode);
    // Intent intent = new Intent(context, gopage);
    // context.startActivity(intent);
}

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();// ww w. java 2 s.  c o  m
            if (exit) {
                activity.setResult(activity.RESULT_CANCELED);
                activity.finish();
            }
        }
    });
    AlertDialog alert = builder.create();
    alert.show();
}

From source file:com.todoroo.astrid.actfm.ActFmCameraModule.java

public static boolean activityResult(Activity activity, int requestCode, int resultCode, Intent data,
        CameraResultCallback cameraResult) {
    if (requestCode == ActFmCameraModule.REQUEST_CODE_CAMERA && resultCode == Activity.RESULT_OK) {
        Bitmap bitmap;//w w w.j  a  v a  2 s. c om
        if (data == null) { // large from camera
            if (lastTempFile != null) {
                bitmap = bitmapFromUri(activity, Uri.fromFile(lastTempFile));
                lastTempFile.deleteOnExit();
                lastTempFile = null;
            } else
                bitmap = null;
        } else
            bitmap = data.getParcelableExtra("data"); //$NON-NLS-1$
        if (bitmap != null) {
            activity.setResult(Activity.RESULT_OK);
            cameraResult.handleCameraResult(bitmap);
        }
        return true;
    } else if (requestCode == ActFmCameraModule.REQUEST_CODE_PICTURE && resultCode == Activity.RESULT_OK) {
        Uri uri = data.getData();
        Bitmap bitmap = bitmapFromUri(activity, uri);
        if (bitmap != null) {
            activity.setResult(Activity.RESULT_OK);
            cameraResult.handleCameraResult(bitmap);
        }
        return true;
    }
    return false;
}

From source file:nz.ac.auckland.lablet.ExperimentAnalysisFragment.java

protected void setupStandardMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.standard_analysis_actions, menu);

    final MenuItem doneItem = menu.findItem(R.id.action_done);
    assert doneItem != null;
    doneItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override//from   w w  w. j a  v  a  2 s .c  om
        public boolean onMenuItemClick(MenuItem menuItem) {
            Activity activity = getActivity();
            activity.setResult(Activity.RESULT_OK);
            activity.finish();
            return true;
        }
    });

    // data menu item
    ExperimentAnalysisActivity experimentActivity = (ExperimentAnalysisActivity) getActivity();
    final ExperimentAnalysis experimentAnalysis = experimentActivity.getExperimentAnalysis();
    final MenuItem dataItem = menu.findItem(R.id.action_data);
    assert dataItem != null;
    dataItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem menuItem) {
            showDataMenu(experimentAnalysis);
            return true;
        }
    });
    // hide item if there is no more than one data
    if (experimentAnalysis.getAnalysisRunAt(analysisRef.runId).analysisList.size() == 1)
        dataItem.setVisible(false);
}

From source file:com.ubuntuone.android.files.fragment.SignInFragment.java

@Override
public void onSuccess() {
    mTracker.trackEvent("Referrer", Analytics.REFERRER, "login", 1);
    mTracker.trackEvent("Referee", Analytics.REFERRER, "login", 1);

    final Activity activity = getActivity();
    activity.setResult(Activity.RESULT_OK);
    activity.finish();/*ww w.  j  a  v  a 2  s .  c  o  m*/
}

From source file:com.ubuntuone.android.files.fragment.SignUpFragment.java

@Override
public void onRegisterUserSuccess(String oauthData) {
    Log.d(TAG, "onRegisterUserSuccess()");

    // XXX This is dead code and needs to be removed. New user will never have
    // an account that is immediately validated after sign-up.

    final Activity activity = getActivity();
    activity.setResult(Activity.RESULT_OK);
    activity.finish();/*from  www .  j  a va 2 s  .c o m*/
}

From source file:fr.cph.stock.android.StockTrackerApp.java

/**
 * This function logout the user and removes its login/password from the preferences. It also loads the login activity
 * //from  w  w w. ja v a  2s  .c o  m
 * @param activity
 *            the activity to finish
 */
public void logOut(Activity activity) {
    SharedPreferences settings = getSharedPreferences(BaseActivity.PREFS_NAME, 0);
    String login = settings.getString("login", null);
    String password = settings.getString("password", null);
    if (login != null) {
        settings.edit().remove("login").commit();
    }
    if (password != null) {
        settings.edit().remove("password").commit();
    }
    activity.setResult(100);
    activity.finish();
    Intent intent = new Intent(this, LoginActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

From source file:com.ichi2.anki.StudyOptionsFragment.java

private void closeStudyOptions(int result) {
    Activity a = getActivity();
    if (!mFragmented && a != null) {
        a.setResult(result);
        a.finish();//  w  w w .j  a v  a2 s  . com
        ActivityTransitionAnimation.slide(a, ActivityTransitionAnimation.RIGHT);
    } else if (a == null) {
        // getActivity() can return null if reference to fragment lingers after parent activity has been closed,
        // which is particularly relevant when using AsyncTasks.
        Timber.e("closeStudyOptions() failed due to getActivity() returning null");
    }
}