IntentUtils { public static Intent getStartActivityIntent(final Context context, final Class clazz, final Bundle extras) { final Intent intent = new Intent(context, clazz); if (!(context instanceof Activity)) { intent.addFlags(FLAG_ACTIVITY_NEW_TASK); } if (extras != null) { intent.putExtras(extras); } return intent; } private  IntentUtils(); static Intent getStartActivityIntent(final Context context, final Class clazz, final Bundle extras); static boolean deviceCanHandleIntent(final Context context, final Intent intent); static boolean isHttpUrl(final String url); static boolean isDeepLink(final String url); static boolean canHandleTwitterUrl(Context context); static boolean canHandleApplicationUrl(Context context, String url); static boolean canHandleApplicationUrl(Context context, String url, boolean logError);  }
@Test public void getStartActivityIntent_withActivityContext_shouldReturnIntentWithoutNewTaskFlag() throws Exception { Context context = new Activity(); final Intent intent = IntentUtils.getStartActivityIntent(context, MoPubBrowser.class, null); assertThat(intent.getComponent().getClassName()).isEqualTo(MoPubBrowser.class.getName()); assertThat(Utils.bitMaskContainsFlag(intent.getFlags(), FLAG_ACTIVITY_NEW_TASK)).isFalse(); assertThat(intent.getExtras()).isNull(); }
@Test public void getStartActivityIntent_withApplicationContext_shouldReturnIntentWithNewTaskFlag() throws Exception { Context context = new Activity().getApplicationContext(); final Intent intent = IntentUtils.getStartActivityIntent(context, MoPubBrowser.class, null); assertThat(intent.getComponent().getClassName()).isEqualTo(MoPubBrowser.class.getName()); assertThat(Utils.bitMaskContainsFlag(intent.getFlags(), FLAG_ACTIVITY_NEW_TASK)).isTrue(); assertThat(intent.getExtras()).isNull(); }
@Test public void getStartActivityIntent_withBundle_shouldReturnIntentWithExtras() throws Exception { Context context = new Activity(); Bundle bundle = new Bundle(); bundle.putString("arbitrary key", "even more arbitrary value"); final Intent intent = IntentUtils.getStartActivityIntent(context, MoPubBrowser.class, bundle); assertThat(intent.getComponent().getClassName()).isEqualTo(MoPubBrowser.class.getName()); assertThat(Utils.bitMaskContainsFlag(intent.getFlags(), FLAG_ACTIVITY_NEW_TASK)).isFalse(); assertThat(intent.getExtras()).isEqualTo(bundle); }