I'm encoutering a very weird problem, when I start the app from the launcher everything is good, but when I start it from a link (in Messenger), the fragment's onCreate/OnCreateView... are called multiple time (but not the activity's)
I have a deep link set to my fragment :
<deepLink
android:id="@+id/deepLink"
app:uri="https://www.mywebsite.com/invitation/{groupId}" />
I'm using Android Navigation Component :
app's build :
apply plugin: "androidx.navigation.safeargs"
def nav_version = "2.0.0"
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"
Main activity :
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Logger.d("ok that s weird");
setContentView(R.layout.activity_main);
Logger.addLogAdapter(new AndroidLogAdapter());
}
}
My fragment :
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
View v = inflater.inflate(R.layout.fragment_welcome, container, false);
apiService=NetworkingManager.getRetrofit().create(ApiService.class);
student = WelcomeFragmentArgs.fromBundle(getArguments()).getStudent();
Logger.d("welcomefragment view being created");
return v;
}
}
My navigation graph :
as you can see Fragment perform create is called twice... and in parallel I guess
New solution:
override fun onNewIntent(intent: Intent?) {
super.onNewIntent(intent)
navController.popBackStack(R.id.home, false)
setIntent(intent)
handleDeepLink()
}
Do the above step in onNewIntent of you MainActivity or where you handle deeplinks.
Not sure if it's good practive @ianhanniballake
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With