Like Deep Link in a snippet in an Android app. Is it possible?

So is it possible to deeply relate a fragment? Thus, my main activity runs different fragments depending on what the user clicks.

So, I created a deep link for my main activity with an intent filter in the manifest file. But how would you do this for a fragment?

Any help would be helpful

Thanks.

+6
source share
1 answer

Of course you can do it. You need to analyze the intention in action and use the fragment manager to fill in the late fragment that you want. Replace the action and fragment with yours.

@Override protected void onNewIntent(final Intent intent) { super.onNewIntent(intent); parseIntent(intent); } private void parseIntent(Intent intent) { final String action = intent.getAction(); if (action != null) { if (Action.<ONE>.equals(action)) { FragmentManager fm = getFragmentManager(); Fragment<ONE> fragment = (Fragment<ONE>) Fragment.instantiate(this, Fragment<ONE>.class.getCanonicalName(), getIntent().getExtras()); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.fragment_id, fragment); ft.commit(); } else if (Action.<TWO>.equals(action)) { FragmentManager fm = getFragmentManager(); Fragment<TWO> fragment = (Fragment<TWO>) Fragment.instantiate(this, Fragment<TWO>.class.getCanonicalName(), getIntent().getExtras()); FragmentTransaction ft = fm.beginTransaction(); ft.add(R.id.fragment_id, fragment); ft.commit(); } } } 

Actions are simply lines that should be unique to a given intent. They can be anything. How:

"myapp.image_included" or "myapp.link_url" etc.

+3
source

All Articles