當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。