下面列出了android.app.ActivityOptions#makeBasic ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@TargetApi(VERSION_CODES.P)
private void relaunchInLockTaskMode() {
ActivityManager activityManager = getContext().getSystemService(ActivityManager.class);
final Intent intent = new Intent(getActivity(), getActivity().getClass());
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
// Ensure a new task is actually created if not already running in lock task mode
if (!activityManager.isInLockTaskMode()){
intent.addFlags(Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
}
final ActivityOptions options = ActivityOptions.makeBasic();
options.setLockTaskEnabled(true);
try {
startActivity(intent, options.toBundle());
getActivity().finish();
} catch (SecurityException e) {
showToast("You must first whitelist the TestDPC package for LockTask");
}
}
public void onStartLaunchBoundsActivity(View view) {
Log.d(mLogTag, "** starting LaunchBoundsActivity");
// Define the bounds in which the Activity will be launched into.
Rect bounds = new Rect(500, 300, 100, 0);
// Set the bounds as an activity option.
ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchBounds(bounds);
// Start the LaunchBoundsActivity with the specified options
Intent intent = new Intent(this, LaunchBoundsActivity.class);
startActivity(intent, options.toBundle());
}
private boolean interceptWorkProfileChallengeIfNeeded() {
final Intent interceptingIntent = interceptWithConfirmCredentialsIfNeeded(mAInfo, mUserId);
if (interceptingIntent == null) {
return false;
}
mIntent = interceptingIntent;
mCallingPid = mRealCallingPid;
mCallingUid = mRealCallingUid;
mResolvedType = null;
// If we are intercepting and there was a task, convert it into an extra for the
// ConfirmCredentials intent and unassign it, as otherwise the task will move to
// front even if ConfirmCredentials is cancelled.
if (mInTask != null) {
mIntent.putExtra(EXTRA_TASK_ID, mInTask.taskId);
mInTask = null;
}
if (mActivityOptions == null) {
mActivityOptions = ActivityOptions.makeBasic();
}
ActivityRecord homeActivityRecord = mSupervisor.getHomeActivity();
if (homeActivityRecord != null && homeActivityRecord.getTask() != null) {
// Showing credential confirmation activity in home task to avoid stopping multi-windowed
// mode after showing the full-screen credential confirmation activity.
mActivityOptions.setLaunchTaskId(homeActivityRecord.getTask().taskId);
}
final UserInfo parent = mUserManager.getProfileParent(mUserId);
mRInfo = mSupervisor.resolveIntent(mIntent, mResolvedType, parent.id, 0, mRealCallingUid);
mAInfo = mSupervisor.resolveActivity(mIntent, mRInfo, mStartFlags, null /*profilerInfo*/);
return true;
}
/**
* Creates an ActivityOptions Bundle with basic options and the LaunchDisplayId set.
* @param displayId The id of the display to launch into.
* @return The created bundle, or null if unsupported.
*/
public static Bundle createLaunchDisplayIdActivityOptions(int displayId) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) return null;
ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchDisplayId(displayId);
return options.toBundle();
}
public void onStartLaunchBoundsActivity(View view) {
Log.d(mLogTag, "** starting LaunchBoundsActivity");
// Define the bounds in which the Activity will be launched into.
Rect bounds = new Rect(500, 300, 100, 0);
// Set the bounds as an activity option.
ActivityOptions options = ActivityOptions.makeBasic();
options.setLaunchBounds(bounds);
// Start the LaunchBoundsActivity with the specified options
Intent intent = new Intent(this, LaunchBoundsActivity.class);
startActivity(intent, options.toBundle());
}