1 /* 2 * Copyright 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package androidx.fragment.app.test; 18 19 import android.content.Intent; 20 import android.os.Bundle; 21 22 import androidx.fragment.app.Fragment; 23 import androidx.fragment.app.FragmentActivity; 24 25 import java.util.concurrent.CountDownLatch; 26 27 public class NewIntentActivity extends FragmentActivity { 28 public final CountDownLatch newIntent = new CountDownLatch(1); 29 30 @Override onCreate(Bundle savedInstanceState)31 public void onCreate(Bundle savedInstanceState) { 32 super.onCreate(savedInstanceState); 33 if (savedInstanceState == null) { 34 getSupportFragmentManager() 35 .beginTransaction() 36 .add(new FooFragment(), "derp") 37 .commitNow(); 38 } 39 } 40 41 @Override onNewIntent(Intent intent)42 public void onNewIntent(Intent intent) { 43 super.onNewIntent(intent); 44 // Test a child fragment transaction - 45 getSupportFragmentManager() 46 .findFragmentByTag("derp") 47 .getChildFragmentManager() 48 .beginTransaction() 49 .add(new FooFragment(), "derp4") 50 .commitNow(); 51 newIntent.countDown(); 52 } 53 54 public static class FooFragment extends Fragment { 55 } 56 } 57