android.util.AndroidRuntimeException Java Examples

The following examples show how to use android.util.AndroidRuntimeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #2
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #3
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in. A bug was existed between N and O-MR1 which allowed this to work. We
    // maintain this for backwards compatibility.
    final int targetSdkVersion = getApplicationInfo().targetSdkVersion;

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && (targetSdkVersion < Build.VERSION_CODES.N
                    || targetSdkVersion >= Build.VERSION_CODES.P)
            && (options == null
                    || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                        + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                        + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #4
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #5
Source Project: CircularReveal   Author: ozodrukh   File: SpringAnimation.java    License: MIT License 6 votes vote down vote up
/**
 * Skips to the end of the animation. If the spring is undamped, an
 * {@link IllegalStateException} will be thrown, as the animation would never reach to an end.
 * It is recommended to check {@link #canSkipToEnd()} before calling this method. This method
 * should only be called on main thread. If animation is not running, no-op.
 *
 * @throws IllegalStateException if the spring is undamped (i.e. damping ratio = 0)
 * @throws AndroidRuntimeException if this method is not called on the main thread
 */
public void skipToEnd() {
  if (!canSkipToEnd()) {
    throw new UnsupportedOperationException("Spring animations can only come to an end"
        + " when there is damping");
  }
  if (Looper.myLooper() != Looper.getMainLooper()) {
    throw new AndroidRuntimeException("Animations may only be started on the main thread");
  }
  if (mRunning) {
    if (mPendingPosition != UNSET) {
      mSpring.setFinalPosition(mPendingPosition);
      mPendingPosition = UNSET;
    }
    mValue = mSpring.getFinalPosition();
    mVelocity = 0;
    cancel();
  }
}
 
Example #6
Source Project: Libraries-for-Android-Developers   Author: eoecn   File: ActionBarSherlockCompat.java    License: MIT License 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #7
Source Project: zhangshangwuda   Author: Consoar   File: ActionBarSherlockCompat.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #8
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in.
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && options != null && ActivityOptions.fromBundle(options).getLaunchTaskId() == -1) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #9
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in. A bug was existed between N and O-MR1 which allowed this to work. We
    // maintain this for backwards compatibility.
    final int targetSdkVersion = getApplicationInfo().targetSdkVersion;

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && (targetSdkVersion < Build.VERSION_CODES.N
                    || targetSdkVersion >= Build.VERSION_CODES.P)
            && (options == null
                    || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                        + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                        + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #10
Source Project: sdl_java_suite   Author: smartdevicelink   File: SdlBroadcastReceiver.java    License: BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * This method will set a new UncaughtExceptionHandler for the current thread. The only
 * purpose of the custom UncaughtExceptionHandler is to catch the rare occurrence that the
 * SdlRouterService can't be started fast enough by the system after calling
 * startForegroundService so the onCreate method doesn't get called before the foreground promise
 * timer expires. The new UncaughtExceptionHandler will catch that specific exception and tell the
 * main looper to continue forward. This still leaves the SdlRouterService killed, but prevents
 * an ANR to the app that makes the startForegroundService call.
 */
static protected void setForegroundExceptionHandler() {
	final Thread.UncaughtExceptionHandler defaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
	if(defaultUncaughtExceptionHandler != foregroundExceptionHandler){
		foregroundExceptionHandler = new Thread.UncaughtExceptionHandler() {
			@Override
			public void uncaughtException(Thread t, Throwable e) {
				if (e != null
						&& e instanceof AndroidRuntimeException
						&& "android.app.RemoteServiceException".equals(e.getClass().getName())  //android.app.RemoteServiceException is a private class
						&& e.getMessage().contains("SdlRouterService")) {

					Log.i(TAG, "Handling failed startForegroundService call");
					Looper.loop();
				} else if (defaultUncaughtExceptionHandler != null) { //No other exception should be handled
					defaultUncaughtExceptionHandler.uncaughtException(t, e);
				}
			}
		};
		Thread.setDefaultUncaughtExceptionHandler(foregroundExceptionHandler);
	}
}
 
Example #11
Source Project: android_9.0.0_r45   Author: lulululbj   File: AnimatorSet.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * <p>Note that canceling a <code>AnimatorSet</code> also cancels all of the animations that it
 * is responsible for.</p>
 */
@SuppressWarnings("unchecked")
@Override
public void cancel() {
    if (Looper.myLooper() == null) {
        throw new AndroidRuntimeException("Animators may only be run on Looper threads");
    }
    if (isStarted()) {
        ArrayList<AnimatorListener> tmpListeners = null;
        if (mListeners != null) {
            tmpListeners = (ArrayList<AnimatorListener>) mListeners.clone();
            int size = tmpListeners.size();
            for (int i = 0; i < size; i++) {
                tmpListeners.get(i).onAnimationCancel(this);
            }
        }
        ArrayList<Node> playingSet = new ArrayList<>(mPlayingSet);
        int setSize = playingSet.size();
        for (int i = 0; i < setSize; i++) {
            playingSet.get(i).mAnimation.cancel();
        }
        mPlayingSet.clear();
        endAnimation();
    }
}
 
Example #12
Source Project: Transitions-Everywhere   Author: andkulikov   File: TransitionSet.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Sets the play order of this set's child transitions.
 *
 * @param ordering {@link #ORDERING_TOGETHER} to play this set's child
 *                 transitions together, {@link #ORDERING_SEQUENTIAL} to play the child
 *                 transitions in sequence.
 * @return This transitionSet object.
 */
@NonNull
public TransitionSet setOrdering(int ordering) {
    switch (ordering) {
        case ORDERING_SEQUENTIAL:
            mPlayTogether = false;
            break;
        case ORDERING_TOGETHER:
            mPlayTogether = true;
            break;
        default:
            throw new AndroidRuntimeException("Invalid parameter for TransitionSet " +
                    "ordering: " + ordering);
    }
    return this;
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: ContextImpl.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();

    // Calling start activity from outside an activity without FLAG_ACTIVITY_NEW_TASK is
    // generally not allowed, except if the caller specifies the task id the activity should
    // be launched in. A bug was existed between N and O-MR1 which allowed this to work. We
    // maintain this for backwards compatibility.
    final int targetSdkVersion = getApplicationInfo().targetSdkVersion;

    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_NEW_TASK) == 0
            && (targetSdkVersion < Build.VERSION_CODES.N
                    || targetSdkVersion >= Build.VERSION_CODES.P)
            && (options == null
                    || ActivityOptions.fromBundle(options).getLaunchTaskId() == -1)) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                        + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                        + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #14
Source Project: zen4android   Author: nihaoyalong   File: ActionBarSherlockCompat.java    License: MIT License 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #15
Source Project: CSipSimple   Author: treasure-lau   File: ActionBarSherlockCompat.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (ActionBarSherlock.DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #16
Source Project: android-wallet-app   Author: iotaledger   File: AboutFragment.java    License: GNU General Public License v3.0 6 votes vote down vote up
@OnClick(R.id.about_licenses)
public void onAboutLicensesClick() {
    try {
        new LicensesDialog.Builder(getActivity())
                .setNotices(R.raw.licenses)
                .setTitle(R.string.about_licenses)
                .setIncludeOwnLicense(true)
                .setCloseText(R.string.buttons_ok)
                .build()
                .showAppCompat();
    } catch (AndroidRuntimeException e) {
        View contentView = getActivity().getWindow().getDecorView();
        Snackbar snackbar = Snackbar.make(contentView,
                R.string.message_open_licenses_error, Snackbar.LENGTH_LONG);
        snackbar.setAction(R.string.message_install_web_view, v -> openPlayStore());
        snackbar.show();
    }
}
 
Example #17
Source Project: android-apps   Author: iamsarker   File: ActionBarSherlockCompat.java    License: MIT License 6 votes vote down vote up
@Override
public boolean requestFeature(int featureId) {
    if (DEBUG) Log.d(TAG, "[requestFeature] featureId: " + featureId);

    if (mContentParent != null) {
        throw new AndroidRuntimeException("requestFeature() must be called before adding content");
    }

    switch (featureId) {
        case Window.FEATURE_ACTION_BAR:
        case Window.FEATURE_ACTION_BAR_OVERLAY:
        case Window.FEATURE_ACTION_MODE_OVERLAY:
        case Window.FEATURE_INDETERMINATE_PROGRESS:
        case Window.FEATURE_NO_TITLE:
        case Window.FEATURE_PROGRESS:
            mFeatures |= (1 << featureId);
            return true;

        default:
            return false;
    }
}
 
Example #18
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivitiesAsUser(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options, userHandle.getIdentifier());
}
 
Example #19
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivities(Intent[] intents, Bundle options) {
    warnIfCallingFromSystemProcess();
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivities(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options);
}
 
Example #20
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivitiesAsUser(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options, userHandle.getIdentifier());
}
 
Example #21
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivities(Intent[] intents, Bundle options) {
    warnIfCallingFromSystemProcess();
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivities(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options);
}
 
Example #22
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    warnIfCallingFromSystemProcess();
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intent, -1, options);
}
 
Example #23
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
public void startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivitiesAsUser(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options, userHandle.getIdentifier());
}
 
Example #24
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivities(Intent[] intents, Bundle options) {
    warnIfCallingFromSystemProcess();
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivities(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options);
}
 
Example #25
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
/** @hide */
@Override
public int startActivitiesAsUser(Intent[] intents, Bundle options, UserHandle userHandle) {
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    return mMainThread.getInstrumentation().execStartActivitiesAsUser(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options, userHandle.getIdentifier());
}
 
Example #26
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivities(Intent[] intents, Bundle options) {
    warnIfCallingFromSystemProcess();
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivities(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options);
}
 
Example #27
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivities(Intent[] intents, Bundle options) {
    warnIfCallingFromSystemProcess();
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivities(
            getOuterContext(), mMainThread.getApplicationThread(), null,
            (Activity) null, intents, options);
}
 
Example #28
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivity(Intent intent, Bundle options) {
    if ((intent.getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivity() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivity(
        getOuterContext(), mMainThread.getApplicationThread(), null,
        (Activity)null, intent, -1, options);
}
 
Example #29
Source Project: AndroidComponentPlugin   Author: androidmalin   File: ContextImpl.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void startActivities(Intent[] intents, Bundle options) {
    if ((intents[0].getFlags()&Intent.FLAG_ACTIVITY_NEW_TASK) == 0) {
        throw new AndroidRuntimeException(
                "Calling startActivities() from outside of an Activity "
                + " context requires the FLAG_ACTIVITY_NEW_TASK flag on first Intent."
                + " Is this really what you want?");
    }
    mMainThread.getInstrumentation().execStartActivities(
        getOuterContext(), mMainThread.getApplicationThread(), null,
        (Activity)null, intents, options);
}
 
Example #30
Source Project: AndroidComponentPlugin   Author: androidmalin   File: Instrumentation.java    License: Apache License 2.0 5 votes vote down vote up
static void checkStartActivityResult(int res, Object intent) {
    if (res >= IActivityManager.START_SUCCESS) {
        return;
    }
    
    switch (res) {
        case IActivityManager.START_INTENT_NOT_RESOLVED:
        case IActivityManager.START_CLASS_NOT_FOUND:
            if (intent instanceof Intent && ((Intent)intent).getComponent() != null)
                throw new ActivityNotFoundException(
                        "Unable to find explicit activity class "
                        + ((Intent)intent).getComponent().toShortString()
                        + "; have you declared this activity in your AndroidManifest.xml?");
            throw new ActivityNotFoundException(
                    "No Activity found to handle " + intent);
        case IActivityManager.START_PERMISSION_DENIED:
            throw new SecurityException("Not allowed to start activity "
                    + intent);
        case IActivityManager.START_FORWARD_AND_REQUEST_CONFLICT:
            throw new AndroidRuntimeException(
                    "FORWARD_RESULT_FLAG used while also requesting a result");
        case IActivityManager.START_NOT_ACTIVITY:
            throw new IllegalArgumentException(
                    "PendingIntent is not an activity");
        default:
            throw new AndroidRuntimeException("Unknown error code "
                    + res + " when starting " + intent);
    }
}