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

The following examples show how to use androidx.fragment.app.FragmentActivity#finish() . 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 void runTest(CollectingLifecycleOwner owner) throws Throwable {
    TestUtils.waitTillResumed(owner, activityRule);
    FragmentActivity dialog = launchDialog();
    assertStateSaving();
    waitForIdle();
    assertThat(owner.copyCollectedEvents(), is(EXPECTED[0]));
    List<Pair<TestEvent, Lifecycle.Event>> expected;
    if (mDismissDialog) {
        dialog.finish();
        TestUtils.waitTillResumed(activityRule.getActivity(), activityRule);
        assertThat(owner.copyCollectedEvents(), is(flatMap(EXPECTED[0], EXPECTED[1])));
        expected = flatMap(EXPECTED[0], EXPECTED[1], EXPECTED[2]);
    } else {
        expected = flatMap(CREATE, START, RESUME, PAUSE, STOP, DESTROY);
    }
    CollectingSupportActivity activity = activityRule.getActivity();
    activityRule.finishActivity();
    TestUtils.waitTillDestroyed(activity, activityRule);
    assertThat(owner.copyCollectedEvents(), is(expected));
}
 
Example 4
Source File: BluetoothChatFragment.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setHasOptionsMenu(true);
    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    FragmentActivity activity = getActivity();
    if (mBluetoothAdapter == null && activity != null) {
        Toast.makeText(activity, "Bluetooth is not available", Toast.LENGTH_LONG).show();
        activity.finish();
    }
}
 
Example 5
Source File: BluetoothChatFragment.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
        case REQUEST_CONNECT_DEVICE_SECURE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                connectDevice(data, true);
            }
            break;
        case REQUEST_CONNECT_DEVICE_INSECURE:
            // When DeviceListActivity returns with a device to connect
            if (resultCode == Activity.RESULT_OK) {
                connectDevice(data, false);
            }
            break;
        case REQUEST_ENABLE_BT:
            // When the request to enable Bluetooth returns
            if (resultCode == Activity.RESULT_OK) {
                // Bluetooth is now enabled, so set up a chat session
                setupChat();
            } else {
                // User did not enable Bluetooth or an error occurred
                Log.d(TAG, "BT not enabled");
                FragmentActivity activity = getActivity();
                if (activity != null) {
                    Toast.makeText(activity, R.string.bt_not_enabled_leaving,
                            Toast.LENGTH_SHORT).show();
                    activity.finish();
                }
            }
    }
}
 
Example 6
Source File: WelcomeFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
  super.onViewCreated(view, savedInstanceState);

  if (isReregister()) {
    RegistrationViewModel model = getModel();

    if (model.hasRestoreFlowBeenShown()) {
      Log.i(TAG, "We've come back to the home fragment on a restore, user must be backing out");
      if (!Navigation.findNavController(view).popBackStack()) {
        FragmentActivity activity = requireActivity();
        activity.finish();
        ActivityNavigator.applyPopAnimationsToPendingTransition(activity);
      }
      return;
    }

    initializeNumber();

    Log.i(TAG, "Skipping restore because this is a reregistration.");
    model.setWelcomeSkippedOnRestore();
    Navigation.findNavController(view)
              .navigate(WelcomeFragmentDirections.actionSkipRestore());

  } else {

    setDebugLogSubmitMultiTapView(view.findViewById(R.id.image));
    setDebugLogSubmitMultiTapView(view.findViewById(R.id.title));

    continueButton = view.findViewById(R.id.welcome_continue_button);
    continueButton.setOnClickListener(this::continueClicked);

    view.findViewById(R.id.welcome_terms_button).setOnClickListener(v -> onTermsClicked());
  }
}
 
Example 7
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 8
Source File: ProcessOwnerTest.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Test
public void testPressHomeButton() throws Throwable {
    setupObserverOnResume();

    Instrumentation.ActivityMonitor monitor = new Instrumentation.ActivityMonitor(
            NavigationDialogActivity.class.getCanonicalName(), null, false);
    Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
    instrumentation.addMonitor(monitor);

    NavigationTestActivityFirst activity = activityTestRule.getActivity();
    activity.startActivity(new Intent(activity, NavigationDialogActivity.class));
    FragmentActivity dialogActivity = (FragmentActivity) monitor.waitForActivity();
    checkProcessObserverSilent(dialogActivity);

    List<Event> events = Collections.synchronizedList(new ArrayList<>());

    LifecycleObserver collectingObserver = new LifecycleObserver() {
        @OnLifecycleEvent(Event.ON_ANY)
        public void onStateChanged(@SuppressWarnings("unused") LifecycleOwner provider,
                Event event) {
            events.add(event);
        }
    };
    addProcessObserver(collectingObserver);
    events.clear();
    assertThat(activity.moveTaskToBack(true), is(true));
    Thread.sleep(ProcessLifecycleOwner.TIMEOUT_MS * 2);
    assertThat(events.toArray(), is(new Event[]{ON_PAUSE, ON_STOP}));
    events.clear();
    Context context = InstrumentationRegistry.getContext();
    context.startActivity(new Intent(activity, NavigationDialogActivity.class)
            .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
    waitTillResumed(dialogActivity, activityTestRule);
    assertThat(events.toArray(), is(new Event[]{ON_START, ON_RESUME}));
    removeProcessObserver(collectingObserver);
    dialogActivity.finish();
}
 
Example 9
Source File: ServerListFragment.java    From igniter with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void selectServerConfig(TrojanConfig config) {
    FragmentActivity activity = getActivity();
    if (activity != null) {
        Intent intent = new Intent();
        intent.putExtra(KEY_TROJAN_CONFIG, config);
        activity.setResult(Activity.RESULT_OK, intent);
        activity.finish();
    }
}
 
Example 10
Source File: BlockedAndShareContactsActivity.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
private void shareContact(String name, String mail) {
  Intent intent = new Intent();
  intent.putExtra(BlockedAndShareContactsActivity.SHARE_CONTACT_NAME_EXTRA, name);
  intent.putExtra(BlockedAndShareContactsActivity.SHARE_CONTACT_MAIL_EXTRA, mail);
  FragmentActivity activity = Objects.requireNonNull(getActivity());
  activity.setResult(RESULT_OK, intent);
  activity.finish();
}
 
Example 11
Source File: EditTaskFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
private void showNoListMessageAndFinish()
{
    Toast.makeText(getContext(), R.string.task_list_selection_empty, Toast.LENGTH_LONG).show();
    FragmentActivity activity = getActivity();
    if (activity != null)
    {
        activity.finish();
    }
}
 
Example 12
Source File: SceneFragment.java    From MHViewer with Apache License 2.0 4 votes vote down vote up
public void finishStage() {
    FragmentActivity activity = getActivity();
    if (activity != null) {
        activity.finish();
    }
}
 
Example 13
Source File: BaseFragment.java    From igniter with GNU General Public License v3.0 4 votes vote down vote up
protected void finishActivity() {
    FragmentActivity activity = getActivity();
    if (activity != null && !activity.isFinishing() && !activity.isDestroyed()) {
        activity.finish();
    }
}
 
Example 14
Source File: SceneFragment.java    From EhViewer with Apache License 2.0 4 votes vote down vote up
public void finishStage() {
    FragmentActivity activity = getActivity();
    if (activity != null) {
        activity.finish();
    }
}