本文整理匯總了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();
}
}
示例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();
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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();
}
}
示例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());
}
示例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();
}
}
}
示例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;
}
示例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();
}
}
示例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();
}
}
示例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();
}
示例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();;
}
示例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();
}
}
示例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);
}