Java Code Examples for androidx.fragment.app.FragmentActivity#startActivity()

The following examples show how to use androidx.fragment.app.FragmentActivity#startActivity() . 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 File: RegistrationCompleteFragment.java    From mollyim-android with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);

  FragmentActivity activity = requireActivity();

  if (SignalStore.storageServiceValues().needsAccountRestore()) {
    activity.startActivity(new Intent(activity, PinRestoreActivity.class));
  } else if (!isReregister()) {
    final Intent main    = new Intent(activity, MainActivity.class);
    final Intent profile = EditProfileActivity.getIntentForUserProfile(activity);

    Intent kbs = CreateKbsPinActivity.getIntentForPinCreate(requireContext());
    activity.startActivity(chainIntents(chainIntents(profile, kbs), main));
  }

  activity.finish();
  ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
}
 
Example 2
Source File: ProcessOwnerTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
@Test
public void testNavigation() throws Throwable {
    FragmentActivity firstActivity = setupObserverOnResume();
    Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(
            NavigationTestActivitySecond.class.getCanonicalName(), null, false);
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.addMonitor(monitor);

    Intent intent = new Intent(firstActivity, NavigationTestActivitySecond.class);
    firstActivity.finish();
    firstActivity.startActivity(intent);

    FragmentActivity secondActivity = (FragmentActivity) monitor.waitForActivity();
    assertThat("Failed to navigate", secondActivity, notNullValue());
    checkProcessObserverSilent(secondActivity);
}
 
Example 3
Source File: PartiallyCoveredActivityTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private FragmentActivity launchDialog() throws Throwable {
    Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(
            NavigationDialogActivity.class.getCanonicalName(), null, false);
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.addMonitor(monitor);

    FragmentActivity activity = activityRule.getActivity();

    Intent intent = new Intent(activity, NavigationDialogActivity.class);
    // disabling animations helps with less flaky API 16 tests
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    activity.startActivity(intent);
    FragmentActivity fragmentActivity = (FragmentActivity) monitor.waitForActivity();
    TestUtils.waitTillResumed(fragmentActivity, activityRule);
    return fragmentActivity;
}
 
Example 4
Source File: LiveDataOnSaveInstanceStateTest.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
private FragmentActivity launchDialog() throws Throwable {
    Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(
            NavigationDialogActivity.class.getCanonicalName(), null, false);
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.addMonitor(monitor);

    FragmentActivity activity = mActivityTestRule.getActivity();
    // helps with less flaky API 16 tests
    Intent intent = new Intent(activity, NavigationDialogActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
    activity.startActivity(intent);
    FragmentActivity fragmentActivity = (FragmentActivity) monitor.waitForActivity();
    TestUtils.waitTillResumed(fragmentActivity, mActivityTestRule);
    return fragmentActivity;
}
 
Example 5
Source File: BrowserUtil.java    From edx-app-android with Apache License 2.0 6 votes vote down vote up
private static void openInBrowser(FragmentActivity context, String url) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.addCategory(Intent.CATEGORY_BROWSABLE);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.setData(Uri.parse(url));
    try {
        context.startActivity(intent);
        AnalyticsRegistry analyticsRegistry = environment.getAnalyticsRegistry();
        analyticsRegistry.trackBrowserLaunched(url);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(context, R.string.cannot_open_url, Toast.LENGTH_SHORT).show();

        // Send non-fatal exception
        logger.error(new Exception(String.format("No activity found (browser cannot handle request) for this url: %s, error:\n", url)
                + e.getMessage()), true);
    }
}
 
Example 6
Source File: ProcessOwnerTest.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Test
public void testNavigationToNonSupport() throws Throwable {
    FragmentActivity firstActivity = setupObserverOnResume();
    Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(
            NonSupportActivity.class.getCanonicalName(), null, false);
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.addMonitor(monitor);

    Intent intent = new Intent(firstActivity, NonSupportActivity.class);
    firstActivity.finish();
    firstActivity.startActivity(intent);
    NonSupportActivity secondActivity = (NonSupportActivity) monitor.waitForActivity();
    assertThat("Failed to navigate", secondActivity, notNullValue());
    checkProcessObserverSilent(secondActivity);
}
 
Example 7
Source File: RuntimePermission.java    From RuntimePermission with Apache License 2.0 5 votes vote down vote up
/**
 * Just a helper methods in case the user blocks permission.
 * It goes to your application settings page for the user to enable permission again.
 */
public void goToSettings() {
    final FragmentActivity fragmentActivity = this.activityReference.get();
    if (fragmentActivity != null) {
        fragmentActivity.startActivity(new Intent(
                Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
                Uri.fromParts("package", fragmentActivity.getPackageName(), null)));
    }
}
 
Example 8
Source File: EmailUtil.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
private static void sendEmailIntent(FragmentActivity activityContext, String to, String subject,
                                    String email){
    Intent email_intent = new Intent(Intent.ACTION_SEND);
    email_intent.putExtra(Intent.EXTRA_EMAIL, new String[] { to });
    email_intent.putExtra(Intent.EXTRA_SUBJECT, subject);
    email_intent.putExtra(Intent.EXTRA_TEXT, email);
    email_intent.setType("plain/text");

    try {
        email_intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

        if(activityContext!=null){
            // add flag to make sure this call works from non-activity context
            Intent targetIntent = Intent.createChooser(email_intent,
                    activityContext.getString(R.string.email_chooser_header));
            targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            activityContext.startActivity(targetIntent);
        }

    } catch (android.content.ActivityNotFoundException ex) {
        //There is no activity which can perform the intended share Intent
        Toast.makeText(activityContext, activityContext.getString(R.string.email_client_not_present),
                Toast.LENGTH_SHORT)
                .show();
        logger.error(ex);
    }
}
 
Example 9
Source File: SongMenuHelper.java    From Music-Player with GNU General Public License v3.0 4 votes vote down vote up
public static boolean handleMenuClick(@NonNull FragmentActivity activity, @NonNull Song song, int menuItemId) {
    switch (menuItemId) {
        case R.id.action_set_as_ringtone:
            if (RingtoneManager.requiresDialog(activity)) {
                RingtoneManager.showDialog(activity);
            } else {
                RingtoneManager ringtoneManager = new RingtoneManager();
                ringtoneManager.setRingtone(activity, song.id);
            }
            return true;
        case R.id.action_share:
            activity.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, activity), null));
            return true;
        case R.id.action_delete_from_device:
            DeleteSongsDialog.create(song).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
            return true;
        case R.id.action_add_to_playlist:
            AddToPlaylistDialog.create(song).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
            return true;
        case R.id.action_play_next:
            MusicPlayerRemote.playNext(song);
            return true;
        case R.id.action_add_to_current_playing:
            MusicPlayerRemote.enqueue(song);
            return true;
        case R.id.action_tag_editor:
            Intent tagEditorIntent = new Intent(activity, SongTagEditorActivity.class);
            tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
            if (activity instanceof PaletteColorHolder)
                tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_PALETTE, ((PaletteColorHolder) activity).getPaletteColor());
            activity.startActivity(tagEditorIntent);
            return true;
        case R.id.action_details:
            SongDetailDialog.create(song).show(activity.getSupportFragmentManager(), "SONG_DETAILS");
            return true;
        case R.id.action_go_to_album:
            NavigationUtil.goToAlbum(activity, song.albumId);
            return true;
        case R.id.action_go_to_artist:
            NavigationUtil.goToArtist(activity, song.artistId);
            return true;
    }
    return false;
}
 
Example 10
Source File: SongMenuHelper.java    From VinylMusicPlayer with GNU General Public License v3.0 4 votes vote down vote up
public static boolean handleMenuClick(@NonNull FragmentActivity activity, @NonNull Song song, int menuItemId) {
    switch (menuItemId) {
        case R.id.action_set_as_ringtone:
            if (RingtoneManager.requiresDialog(activity)) {
                RingtoneManager.showDialog(activity);
            } else {
                RingtoneManager ringtoneManager = new RingtoneManager();
                ringtoneManager.setRingtone(activity, song.id);
            }
            return true;
        case R.id.action_share:
            activity.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, activity), null));
            return true;
        case R.id.action_delete_from_device:
            DeleteSongsDialog.create(song).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
            return true;
        case R.id.action_add_to_playlist:
            AddToPlaylistDialog.create(song).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
            return true;
        case R.id.action_play_next:
            MusicPlayerRemote.playNext(song);
            return true;
        case R.id.action_add_to_current_playing:
            MusicPlayerRemote.enqueue(song);
            return true;
        case R.id.action_tag_editor:
            Intent tagEditorIntent = new Intent(activity, SongTagEditorActivity.class);
            tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
            if (activity instanceof PaletteColorHolder)
                tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_PALETTE, ((PaletteColorHolder) activity).getPaletteColor());
            activity.startActivity(tagEditorIntent);
            return true;
        case R.id.action_details:
            SongDetailDialog.create(song).show(activity.getSupportFragmentManager(), "SONG_DETAILS");
            return true;
        case R.id.action_go_to_album:
            NavigationUtil.goToAlbum(activity, song.albumId);
            return true;
        case R.id.action_go_to_artist:
            NavigationUtil.goToArtist(activity, song.artistId);
            return true;
    }
    return false;
}
 
Example 11
Source File: SongMenuHelper.java    From Phonograph with GNU General Public License v3.0 4 votes vote down vote up
public static boolean handleMenuClick(@NonNull FragmentActivity activity, @NonNull Song song, int menuItemId) {
    switch (menuItemId) {
        case R.id.action_set_as_ringtone:
            if (RingtoneManager.requiresDialog(activity)) {
                RingtoneManager.showDialog(activity);
            } else {
                RingtoneManager ringtoneManager = new RingtoneManager();
                ringtoneManager.setRingtone(activity, song.id);
            }
            return true;
        case R.id.action_share:
            activity.startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, activity), null));
            return true;
        case R.id.action_delete_from_device:
            DeleteSongsDialog.create(song).show(activity.getSupportFragmentManager(), "DELETE_SONGS");
            return true;
        case R.id.action_add_to_playlist:
            AddToPlaylistDialog.create(song).show(activity.getSupportFragmentManager(), "ADD_PLAYLIST");
            return true;
        case R.id.action_play_next:
            MusicPlayerRemote.playNext(song);
            return true;
        case R.id.action_add_to_current_playing:
            MusicPlayerRemote.enqueue(song);
            return true;
        case R.id.action_tag_editor:
            Intent tagEditorIntent = new Intent(activity, SongTagEditorActivity.class);
            tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_ID, song.id);
            if (activity instanceof PaletteColorHolder)
                tagEditorIntent.putExtra(AbsTagEditorActivity.EXTRA_PALETTE, ((PaletteColorHolder) activity).getPaletteColor());
            activity.startActivity(tagEditorIntent);
            return true;
        case R.id.action_details:
            SongDetailDialog.create(song).show(activity.getSupportFragmentManager(), "SONG_DETAILS");
            return true;
        case R.id.action_go_to_album:
            NavigationUtil.goToAlbum(activity, song.albumId);
            return true;
        case R.id.action_go_to_artist:
            NavigationUtil.goToArtist(activity, song.artistId);
            return true;
    }
    return false;
}
 
Example 12
Source File: PermissionBitte.java    From permission-bitte with MIT License 2 votes vote down vote up
/**
 * Just a helper methods in case the user blocks permission.
 * It goes to your application settings page for the user to enable permission again.
 *
 * @param activity an Activity
 */
public static void goToSettings(FragmentActivity activity) {
  activity.startActivity(new Intent(
          Settings.ACTION_APPLICATION_DETAILS_SETTINGS,
          Uri.fromParts("package", activity.getPackageName(), null)));
}