Java Code Examples for androidx.fragment.app.Fragment#onResume()

The following examples show how to use androidx.fragment.app.Fragment#onResume() . 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: FragmentTabAdapter.java    From ZhiHuIndex with Apache License 2.0 6 votes vote down vote up
@Override
public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
	for (int i = 0; i < rgs.getChildCount(); i++) {
		if (rgs.getChildAt(i).getId() == checkedId) {
			Fragment fragment = fragments.get(i);
			FragmentTransaction ft = obtainFragmentTransaction(i);
			getCurrentFragment().onPause(); 
			if (fragment.isAdded()) {
				fragment.onResume(); 
			} else {
				ft.add(fragmentContentId, fragment);
			}
			showTab(i); 
			ft.commit();

			
			if (null != onRgsExtraCheckedChangedListener) {
				onRgsExtraCheckedChangedListener.OnRgsExtraCheckedChanged(
						radioGroup, checkedId, i);
			}

		}
	}

}
 
Example 2
Source File: RxPreferenceFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(provider.bindUntilEvent(STOP)).test();

    fragment.onAttach(null);
    testObserver.assertNotComplete();
    fragment.onCreate(null);
    testObserver.assertNotComplete();
    fragment.onViewCreated(null, null);
    testObserver.assertNotComplete();
    fragment.onStart();
    testObserver.assertNotComplete();
    fragment.onResume();
    testObserver.assertNotComplete();
    fragment.onPause();
    testObserver.assertNotComplete();
    fragment.onStop();
    testObserver.assertComplete();
}
 
Example 3
Source File: RxSupportFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(provider.bindUntilEvent(STOP)).test();

    fragment.onAttach(null);
    testObserver.assertNotComplete();
    fragment.onCreate(null);
    testObserver.assertNotComplete();
    fragment.onViewCreated(null, null);
    testObserver.assertNotComplete();
    fragment.onStart();
    testObserver.assertNotComplete();
    fragment.onResume();
    testObserver.assertNotComplete();
    fragment.onPause();
    testObserver.assertNotComplete();
    fragment.onStop();
    testObserver.assertComplete();
}
 
Example 4
Source File: RxPreferenceFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
private void testLifecycle(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    TestObserver<FragmentEvent> testObserver = provider.lifecycle().skip(1).test();

    fragment.onAttach(null);
    fragment.onCreate(null);
    fragment.onViewCreated(null, null);
    fragment.onStart();
    fragment.onResume();
    fragment.onPause();
    fragment.onStop();
    fragment.onDestroyView();
    fragment.onDestroy();
    fragment.onDetach();

    testObserver.assertValues(
        FragmentEvent.ATTACH,
        FragmentEvent.CREATE,
        FragmentEvent.CREATE_VIEW,
        FragmentEvent.START,
        FragmentEvent.RESUME,
        FragmentEvent.PAUSE,
        FragmentEvent.STOP,
        FragmentEvent.DESTROY_VIEW,
        FragmentEvent.DESTROY,
        FragmentEvent.DETACH
    );
}
 
Example 5
Source File: RxSupportFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
private void testLifecycle(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    TestObserver<FragmentEvent> testObserver = provider.lifecycle().skip(1).test();

    fragment.onAttach(null);
    fragment.onCreate(null);
    fragment.onViewCreated(null, null);
    fragment.onStart();
    fragment.onResume();
    fragment.onPause();
    fragment.onStop();
    fragment.onDestroyView();
    fragment.onDestroy();
    fragment.onDetach();

    testObserver.assertValues(
        FragmentEvent.ATTACH,
        FragmentEvent.CREATE,
        FragmentEvent.CREATE_VIEW,
        FragmentEvent.START,
        FragmentEvent.RESUME,
        FragmentEvent.PAUSE,
        FragmentEvent.STOP,
        FragmentEvent.DESTROY_VIEW,
        FragmentEvent.DESTROY,
        FragmentEvent.DETACH
    );
}
 
Example 6
Source File: RxPreferenceFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 4 votes vote down vote up
private void testBindToLifecycle(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    fragment.onAttach(null);
    TestObserver<Object> attachObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onCreate(null);
    attachObserver.assertNotComplete();
    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onViewCreated(null, null);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    TestObserver<Object> createViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStart();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onResume();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onPause();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStop();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroyView();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertComplete();
    stopObserver.assertComplete();
    TestObserver<Object> destroyViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroy();
    attachObserver.assertNotComplete();
    createObserver.assertComplete();
    destroyViewObserver.assertComplete();
    TestObserver<Object> destroyObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDetach();
    attachObserver.assertComplete();
    destroyObserver.assertComplete();
}
 
Example 7
Source File: RxSupportFragmentLifecycleTest.java    From RxLifecycle with Apache License 2.0 4 votes vote down vote up
private void testBindToLifecycle(LifecycleProvider<FragmentEvent> provider) {
    Fragment fragment = (Fragment) provider;
    startFragment(fragment);

    fragment.onAttach(null);
    TestObserver<Object> attachObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onCreate(null);
    attachObserver.assertNotComplete();
    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onViewCreated(null, null);
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    TestObserver<Object> createViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStart();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onResume();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onPause();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onStop();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroyView();
    attachObserver.assertNotComplete();
    createObserver.assertNotComplete();
    createViewObserver.assertComplete();
    stopObserver.assertComplete();
    TestObserver<Object> destroyViewObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDestroy();
    attachObserver.assertNotComplete();
    createObserver.assertComplete();
    destroyViewObserver.assertComplete();
    TestObserver<Object> destroyObserver = observable.compose(provider.bindToLifecycle()).test();

    fragment.onDetach();
    attachObserver.assertComplete();
    destroyObserver.assertComplete();
}