当前位置: 首页>>代码示例>>Java>>正文


Java Activity.setResult方法代码示例

本文整理汇总了Java中android.app.Activity.setResult方法的典型用法代码示例。如果您正苦于以下问题:Java Activity.setResult方法的具体用法?Java Activity.setResult怎么用?Java Activity.setResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.app.Activity的用法示例。


在下文中一共展示了Activity.setResult方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: finishShareToMessenger

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Finishes the activity and returns the media item the user picked to Messenger.
 *
 * @param activity the activity that received the original intent from Messenger
 * @param shareToMessengerParams parameters for what to share
 */
public static void finishShareToMessenger(
    Activity activity,
    ShareToMessengerParams shareToMessengerParams) {
  Intent originalIntent = activity.getIntent();
  Set<String> categories = originalIntent.getCategories();
  if (categories == null) {
    // This shouldn't happen.
    activity.setResult(Activity.RESULT_CANCELED, null);
    activity.finish();
    return;
  }

  if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) {
    Bundle appLinkExtras = AppLinks.getAppLinkExtras(originalIntent);

    Intent resultIntent = new Intent();
    if (categories.contains(ORCA_THREAD_CATEGORY_20150314)) {
      resultIntent.putExtra(EXTRA_PROTOCOL_VERSION, MessengerUtils.PROTOCOL_VERSION_20150314);
      String threadToken = appLinkExtras.getString(MessengerUtils.EXTRA_THREAD_TOKEN_KEY);
      resultIntent.putExtra(EXTRA_THREAD_TOKEN_KEY, threadToken);
    } else {
      throw new RuntimeException(); // Can't happen.
    }
    resultIntent.setDataAndType(shareToMessengerParams.uri, shareToMessengerParams.mimeType);
    resultIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    resultIntent.putExtra(EXTRA_APP_ID, FacebookSdk.getApplicationId());
    resultIntent.putExtra(EXTRA_METADATA, shareToMessengerParams.metaData);
    resultIntent.putExtra(EXTRA_EXTERNAL_URI, shareToMessengerParams.externalUri);
    activity.setResult(Activity.RESULT_OK, resultIntent);
    activity.finish();
  } else {
    // This shouldn't happen.
    activity.setResult(Activity.RESULT_CANCELED, null);
    activity.finish();
  }
}
 
开发者ID:eviltnan,项目名称:kognitivo,代码行数:43,代码来源:MessengerUtils.java

示例2: finishWithError

import android.app.Activity; //导入方法依赖的package包/类
protected void finishWithError(final FileStorageSetupActivity setupAct, Exception error) {
	logDebug( "Exception: " + error.toString());
	error.printStackTrace();
	
	final Activity activity = (Activity)setupAct;
	
	int resultCode = Activity.RESULT_CANCELED;
	
	//check if we should return OK anyways.
	//This can make sense if there is a higher-level FileStorage which has the file cached.
	if (activity.getIntent().getBooleanExtra(EXTRA_ALWAYS_RETURN_SUCCESS, false))
	{
		logDebug("Returning success as desired in intent despite of exception.");
		finishActivityWithSuccess(setupAct);
		return;
	}

	Intent retData = new Intent();
	retData.putExtra(EXTRA_ERROR_MESSAGE, error.getMessage());
	activity.setResult(resultCode, retData);
	activity.finish();
}
 
开发者ID:PhilippC,项目名称:keepass2android,代码行数:23,代码来源:JavaFileStorageBase.java

示例3: sysLogout

import android.app.Activity; //导入方法依赖的package包/类
public static void sysLogout(Activity activity) {
    if (PreferencesManager.getInstance().isVip()) {
        DownloadManager.pauseVipDownloadTask();
    }
    LoginManager.getLoginManager().unBindLogin(activity);
    LoginManager.getLoginManager().sendLogInOutIntent("logout_success", activity);
    PreferencesManager.getInstance().logoutUser();
    PreferencesManager.getInstance().setUserPhoneNumberBindState(false);
    LoginManager.getLoginManager().LogoutUser(activity);
    LogInfo.log("ZSM", "ID == " + PreferencesManager.getInstance().getUserId());
    UserInfoTools.logout(activity);
    RedPacketSdkManager.getInstance().setUid("");
    RedPacketSdkManager.getInstance().setToken("");
    try {
        LeMessageManager.getInstance().dispatchMessage(activity, new LeMessage(LeMessageIds.MSG_WEBVIEW_SYNC_LOGIN));
        activity.setResult(9528);
        activity.finish();
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:22,代码来源:PersonalInfoFragment.java

示例4: setResultDataForLogin

import android.app.Activity; //导入方法依赖的package包/类
public static void setResultDataForLogin(Activity activity, Intent intent) {
    if (intent == null) {
        activity.setResult(Constants.RESULT_LOGIN, intent);
        return;
    }
    try {
        Object stringExtra = intent.getStringExtra(Constants.KEY_RESPONSE);
        f.b(TAG, "AssistActivity--setResultDataForLogin-- " + stringExtra);
        if (!TextUtils.isEmpty(stringExtra)) {
            JSONObject jSONObject = new JSONObject(stringExtra);
            CharSequence optString = jSONObject.optString("openid");
            CharSequence optString2 = jSONObject.optString("access_token");
            if (TextUtils.isEmpty(optString) || TextUtils.isEmpty(optString2)) {
                activity.setResult(LetvBaseWebViewActivity.Login_OK, intent);
            } else {
                activity.setResult(Constants.RESULT_LOGIN, intent);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:23,代码来源:AssistActivity.java

示例5: finishAffinity

import android.app.Activity; //导入方法依赖的package包/类
@TargetApi(16)
public static void finishAffinity(Activity activity, int resultCode) {
    if (activity != null) {
        if (VERSION.SDK_INT >= 16) {
            activity.finishAffinity();
            return;
        }
        activity.setResult(resultCode);
        activity.finish();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:12,代码来源:CommonUtils.java

示例6: setResultDataForLogin

import android.app.Activity; //导入方法依赖的package包/类
public static void setResultDataForLogin(Activity activity, Intent intent) {
    if (intent == null) {
        activity.setResult(10101, intent);
        return;
    }
    try {
        Object stringExtra = intent.getStringExtra(Constants.KEY_RESPONSE);
        f.b(TAG, "AssistActivity--setResultDataForLogin-- " + stringExtra);
        if (!TextUtils.isEmpty(stringExtra)) {
            JSONObject jSONObject = new JSONObject(stringExtra);
            CharSequence optString = jSONObject.optString("openid");
            CharSequence optString2 = jSONObject.optString("access_token");
            if (TextUtils.isEmpty(optString) || TextUtils.isEmpty(optString2)) {
                activity.setResult(12345, intent);
            } else {
                activity.setResult(10101, intent);
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:AssistActivity.java

示例7: setActivityResult

import android.app.Activity; //导入方法依赖的package包/类
public void setActivityResult(Activity activity, ScreenResult screenResult, NavigationFactory navigationFactory) throws NavigationException {
	Class<? extends Screen> screenClass = navigationFactory.getScreenClass(activity);
	if (screenClass == null) {
		throw new NavigationException("Failed to get a screen class for " + activity.getClass().getSimpleName());
	}

	ActivityScreenImplementation activityScreenImplementation = (ActivityScreenImplementation) navigationFactory.getScreenImplementation(screenClass);
	if (activityScreenImplementation == null) {
		throw new NavigationException("Failed to get a screen implementation for " + screenClass.getSimpleName());
	}

	if (activityScreenImplementation.getScreenResultClass() == null) {
		throw new NavigationException("Screen " + screenClass.getSimpleName() + " can't return a result.");
	}

	Class<? extends ScreenResult> supportedScreenResultClass = activityScreenImplementation.getScreenResultClass();
	if (!supportedScreenResultClass.isAssignableFrom(screenResult.getClass())) {
		throw new NavigationException("Screen " + screenClass.getSimpleName() + " can't return a result of class " + screenResult.getClass().getCanonicalName() +
		                              ". It returns a result of class " + supportedScreenResultClass.getCanonicalName());
	}

	ActivityResult activityResult = activityScreenImplementation.createActivityResult(screenResult);
	activity.setResult(activityResult.getResultCode(), activityResult.getIntent());
}
 
开发者ID:aartikov,项目名称:Alligator,代码行数:25,代码来源:ScreenResultHelper.java

示例8: finishAllTheActivities

import android.app.Activity; //导入方法依赖的package包/类
/**
* Finish all the instances of the given Activity.
* @param targetActivity The class name of the target Activity.
* @param result The result code to propagate back to the originating activity.
* @param data The data to propagate back to the originating activity.
*/
protected static void finishAllTheActivities(String targetActivity, int result, Intent data) {
    List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
    for (WeakReference<Activity> weakActivity : activities) {
        Activity activity = weakActivity.get();
        if (activity != null && activity.getLocalClassName().equals(targetActivity)) {
            activity.setResult(result, data);
            activity.finish();
        }
    }
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:17,代码来源:FirstRunActivity.java

示例9: launchFirstRunExperience

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Tries to launch the First Run Experience.  If ChromeLauncherActivity is running with the
 * wrong Intent flags, we instead relaunch ChromeLauncherActivity to make sure it runs in its
 * own task, which then triggers First Run.
 * @return Whether or not the First Run Experience needed to be shown.
 * @param forTabbedMode Whether the First Run Experience is launched for tabbed mode.
 */
private boolean launchFirstRunExperience(boolean forTabbedMode) {
    // Tries to launch the Generic First Run Experience for intent from GSA.
    boolean showLightweightFre =
            IntentHandler.determineExternalIntentSource(this.getPackageName(), getIntent())
            != ExternalAppId.GSA;
    Intent freIntent = FirstRunFlowSequencer.checkIfFirstRunIsNecessary(
            this, getIntent(), showLightweightFre);
    if (freIntent == null) return false;

    if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) != 0) {
        if (CommandLine.getInstance().hasSwitch(
                    ChromeSwitches.ENABLE_LIGHTWEIGHT_FIRST_RUN_EXPERIENCE)) {
            boolean isTabbedModeActive = false;
            boolean isLightweightFreActive = false;
            boolean isGenericFreActive = false;
            List<WeakReference<Activity>> activities = ApplicationStatus.getRunningActivities();
            for (WeakReference<Activity> weakActivity : activities) {
                Activity activity = weakActivity.get();
                if (activity == null) {
                    continue;
                }

                if (activity instanceof ChromeTabbedActivity) {
                    isTabbedModeActive = true;
                    continue;
                }

                if (activity instanceof LightweightFirstRunActivity) {
                    isLightweightFreActive = true;
                    // A Generic or a new Lightweight First Run Experience will be launched
                    // below, so finish the old Lightweight First Run Experience.
                    activity.setResult(Activity.RESULT_CANCELED);
                    activity.finish();
                    continue;
                }

                if (activity instanceof FirstRunActivity) {
                    isGenericFreActive = true;
                    continue;
                }
            }

            if (forTabbedMode) {
                if (isTabbedModeActive || isLightweightFreActive || !showLightweightFre) {
                    // Lets ChromeTabbedActivity checks and launches the Generic First Run
                    // Experience.
                    launchTabbedMode(false);
                    finish();
                    return true;
                }
            } else if (isGenericFreActive) {
                // Launch the Generic First Run Experience if it is active previously.
                freIntent = FirstRunFlowSequencer.createGenericFirstRunIntent(
                        this, TextUtils.equals(getIntent().getAction(), Intent.ACTION_MAIN));
            }
        }
        // Add a PendingIntent so that the intent used to launch Chrome will be resent when
        // first run is completed or canceled.
        FirstRunFlowSequencer.addPendingIntent(this, freIntent, getIntent());
        freIntent.putExtra(FirstRunActivity.EXTRA_FINISH_ON_TOUCH_OUTSIDE, !forTabbedMode);
        startActivity(freIntent);
    } else {
        Intent newIntent = new Intent(getIntent());
        newIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(newIntent);
    }
    finish();
    return true;
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:77,代码来源:ChromeLauncherActivity.java

示例10: navigateBack

import android.app.Activity; //导入方法依赖的package包/类
@Override
public void navigateBack(boolean success) {
    Activity activity = getActivity();
    if (activity != null) {
        activity.setResult(success ? Activity.RESULT_OK : Activity.RESULT_CANCELED);
        activity.finish();
    }
}
 
开发者ID:BioID-GmbH,项目名称:BWS-Android,代码行数:9,代码来源:FacialRecognitionFragment.java

示例11: logErrorAndFinish

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Sometimes accessing the camera is not possible (e.g. the camera driver does perform a disconnect).
 * In these cases the activity will be closed.
 */
private void logErrorAndFinish(@NonNull String msg, Object... args) {
    log.e(msg, args);

    Activity activity = getActivity();
    if (activity != null) {
        activity.setResult(Activity.RESULT_CANCELED);
        activity.finish();
    }
}
 
开发者ID:BioID-GmbH,项目名称:BWS-Android,代码行数:14,代码来源:FacialRecognitionFragment.java

示例12: setResultAndFinish

import android.app.Activity; //导入方法依赖的package包/类
/**
 * 设置返回值并关闭页面
 *
 * @param activity    activity
 * @param videoPath   压缩地址
 * @param thumblePath 视频截图地址
 * @param originPath  当前地址
 */
static void setResultAndFinish(Activity activity, String videoPath, String thumblePath, String originPath) {
    Intent i = new Intent();
    i.putExtra(MEDIA_PATH, StringUtil.removeEmpty(videoPath, ""));
    i.putExtra(MEDIA_THUMBLE_PATH, StringUtil.removeEmpty(thumblePath, ""));
    i.putExtra(MEDIA_ORIGIN_PATH, StringUtil.removeEmpty(originPath, ""));
    activity.setResult(activity.RESULT_OK, i);
    activity.finish();
}
 
开发者ID:f-evil,项目名称:EVideoRecorder,代码行数:17,代码来源:ERecorderActivityImpl.java

示例13: finishWithResult

import android.app.Activity; //导入方法依赖的package包/类
/**
 * Finish the activity with your given result code and or intent and or params.
 * @param activity
 *  The activity that will be finish, it's finish() will be called in this method.
 */
public void finishWithResult(Activity activity) {
    Intent in = intent;
    if(params != null) {
        in = in == null ? params.buildIntent() : in.putExtras(params.buildIntent().getExtras());
    }
    if(in != null) {
        activity.setResult(code, in);
    } else {
        activity.setResult(code);
    }
    activity.finish();;
}
 
开发者ID:foreveruseful,项目名称:smartkey,代码行数:18,代码来源:BackResult.java

示例14: Dismiss

import android.app.Activity; //导入方法依赖的package包/类
private void Dismiss(int resultCode) {
    Intent i = new Intent();
    Activity a = getActivity();
    if (a != null) {
        a.setResult(resultCode, i);
        a.finish();
    }
}
 
开发者ID:ericberman,项目名称:MyFlightbookAndroid,代码行数:9,代码来源:ActNewAircraft.java

示例15: backResult

import android.app.Activity; //导入方法依赖的package包/类
public static void backResult(Activity sourceActivity, int resultCode, Bundle bdl) {
    Intent intent = new Intent();
    if (bdl != null) {
        intent.putExtras(bdl);
    }
    sourceActivity.setResult(resultCode, intent);
}
 
开发者ID:vsona,项目名称:RxJava2RetrofitDemo,代码行数:8,代码来源:ActivityUtils.java


注:本文中的android.app.Activity.setResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。