Deeplink into another fragment [ANDROID]










0















The structure of activity and fragment is like :



Using NavigationDrawer.



MainActivity has a container for Fragment, in one container there should be have many fragment. After launch the app, default of fragment is fragment A.



Implement deeplink into MainActivity with Fragment B, how I can change the fragment from Fragment A(default) into Fragment B (destination).



Any help will helpfull :)
Thanks



i.e
class handle Applink



 override fun onInitView() 
handleIntent()


private fun handleIntent()
// ATTENTION: This was auto-generated to handle app links.
val intent = intent
val appLinkAction = intent.action
val appLinkData = intent.data
if (appLinkData != null)
handleAppLinkIntent(appLinkData)
else
handleActivityIntent(intent)



protected abstract fun handleActivityIntent(intent: Intent)

protected abstract fun handleAppLinkIntent(appLinkData: Uri)


impl function



 @Override
protected void handleActivityIntent(Intent intent)
Bundle bundle = intent.getExtras();
if (bundle != null)
switch (this.paramMainMenu)
case Constants.ZERO:
this.goToProductList();
break;
case Constants.ONE:
this.goToFragmentA();
break;
case Constants.TWO:
this.goToFragmentB();
break;
case Constants.THREE:
this.goToFragmentC();
break;




@Override
protected void handleAppLinkIntent(Uri appLinkData)
if(appLinkData.getQueryParameterNames().isEmpty())
String path = appLinkData.getPath();
switch (path)
case "/kfc/food/price/outofstock":
this.paramMainMenu = Constants.ONE;
break;
case "/food/price/qty":
this.paramMainMenu = Constants.THREE;
break;
case "/price/unbuyable":
this.paramMainMenu = Constants.TWO;
break;
case "/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/food/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/a/food/item":
this.paramMainMenu = Constants.ZERO;
break;
case "/":
this.paramMainMenu = Constants.ZERO;
break;












share|improve this question
























  • Use NavigationDrawer, BottomNavigation or ViewPager.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:23












  • using NavigationDrawer @ZwalPyaeKyaw

    – Nadya Prabaningrum
    Nov 13 '18 at 4:25







  • 1





    You can use FragmentManager() to switch between Fragments.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:28











  • getSupportFragmentManager().beginTransaction(). replace(R.id.flContainer, new DemoFragment(), "SOMETAG"). commit(); // Now later we can lookup the fragment by tag DemoFragment fragmentDemo = (DemoFragment) getSupportFragmentManager().findFragmentByTag("SOMETAG"); like this. Here's the link to tutorial.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:33











  • I've use that, the function is the same with clickListener on NavigationDrawer menu. now the problem is when I call the function of switch fragment into handleIntent on Applink, there is no effect. I'm always goto fragment A.

    – Nadya Prabaningrum
    Nov 13 '18 at 4:35















0















The structure of activity and fragment is like :



Using NavigationDrawer.



MainActivity has a container for Fragment, in one container there should be have many fragment. After launch the app, default of fragment is fragment A.



Implement deeplink into MainActivity with Fragment B, how I can change the fragment from Fragment A(default) into Fragment B (destination).



Any help will helpfull :)
Thanks



i.e
class handle Applink



 override fun onInitView() 
handleIntent()


private fun handleIntent()
// ATTENTION: This was auto-generated to handle app links.
val intent = intent
val appLinkAction = intent.action
val appLinkData = intent.data
if (appLinkData != null)
handleAppLinkIntent(appLinkData)
else
handleActivityIntent(intent)



protected abstract fun handleActivityIntent(intent: Intent)

protected abstract fun handleAppLinkIntent(appLinkData: Uri)


impl function



 @Override
protected void handleActivityIntent(Intent intent)
Bundle bundle = intent.getExtras();
if (bundle != null)
switch (this.paramMainMenu)
case Constants.ZERO:
this.goToProductList();
break;
case Constants.ONE:
this.goToFragmentA();
break;
case Constants.TWO:
this.goToFragmentB();
break;
case Constants.THREE:
this.goToFragmentC();
break;




@Override
protected void handleAppLinkIntent(Uri appLinkData)
if(appLinkData.getQueryParameterNames().isEmpty())
String path = appLinkData.getPath();
switch (path)
case "/kfc/food/price/outofstock":
this.paramMainMenu = Constants.ONE;
break;
case "/food/price/qty":
this.paramMainMenu = Constants.THREE;
break;
case "/price/unbuyable":
this.paramMainMenu = Constants.TWO;
break;
case "/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/food/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/a/food/item":
this.paramMainMenu = Constants.ZERO;
break;
case "/":
this.paramMainMenu = Constants.ZERO;
break;












share|improve this question
























  • Use NavigationDrawer, BottomNavigation or ViewPager.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:23












  • using NavigationDrawer @ZwalPyaeKyaw

    – Nadya Prabaningrum
    Nov 13 '18 at 4:25







  • 1





    You can use FragmentManager() to switch between Fragments.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:28











  • getSupportFragmentManager().beginTransaction(). replace(R.id.flContainer, new DemoFragment(), "SOMETAG"). commit(); // Now later we can lookup the fragment by tag DemoFragment fragmentDemo = (DemoFragment) getSupportFragmentManager().findFragmentByTag("SOMETAG"); like this. Here's the link to tutorial.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:33











  • I've use that, the function is the same with clickListener on NavigationDrawer menu. now the problem is when I call the function of switch fragment into handleIntent on Applink, there is no effect. I'm always goto fragment A.

    – Nadya Prabaningrum
    Nov 13 '18 at 4:35













0












0








0


0






The structure of activity and fragment is like :



Using NavigationDrawer.



MainActivity has a container for Fragment, in one container there should be have many fragment. After launch the app, default of fragment is fragment A.



Implement deeplink into MainActivity with Fragment B, how I can change the fragment from Fragment A(default) into Fragment B (destination).



Any help will helpfull :)
Thanks



i.e
class handle Applink



 override fun onInitView() 
handleIntent()


private fun handleIntent()
// ATTENTION: This was auto-generated to handle app links.
val intent = intent
val appLinkAction = intent.action
val appLinkData = intent.data
if (appLinkData != null)
handleAppLinkIntent(appLinkData)
else
handleActivityIntent(intent)



protected abstract fun handleActivityIntent(intent: Intent)

protected abstract fun handleAppLinkIntent(appLinkData: Uri)


impl function



 @Override
protected void handleActivityIntent(Intent intent)
Bundle bundle = intent.getExtras();
if (bundle != null)
switch (this.paramMainMenu)
case Constants.ZERO:
this.goToProductList();
break;
case Constants.ONE:
this.goToFragmentA();
break;
case Constants.TWO:
this.goToFragmentB();
break;
case Constants.THREE:
this.goToFragmentC();
break;




@Override
protected void handleAppLinkIntent(Uri appLinkData)
if(appLinkData.getQueryParameterNames().isEmpty())
String path = appLinkData.getPath();
switch (path)
case "/kfc/food/price/outofstock":
this.paramMainMenu = Constants.ONE;
break;
case "/food/price/qty":
this.paramMainMenu = Constants.THREE;
break;
case "/price/unbuyable":
this.paramMainMenu = Constants.TWO;
break;
case "/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/food/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/a/food/item":
this.paramMainMenu = Constants.ZERO;
break;
case "/":
this.paramMainMenu = Constants.ZERO;
break;












share|improve this question
















The structure of activity and fragment is like :



Using NavigationDrawer.



MainActivity has a container for Fragment, in one container there should be have many fragment. After launch the app, default of fragment is fragment A.



Implement deeplink into MainActivity with Fragment B, how I can change the fragment from Fragment A(default) into Fragment B (destination).



Any help will helpfull :)
Thanks



i.e
class handle Applink



 override fun onInitView() 
handleIntent()


private fun handleIntent()
// ATTENTION: This was auto-generated to handle app links.
val intent = intent
val appLinkAction = intent.action
val appLinkData = intent.data
if (appLinkData != null)
handleAppLinkIntent(appLinkData)
else
handleActivityIntent(intent)



protected abstract fun handleActivityIntent(intent: Intent)

protected abstract fun handleAppLinkIntent(appLinkData: Uri)


impl function



 @Override
protected void handleActivityIntent(Intent intent)
Bundle bundle = intent.getExtras();
if (bundle != null)
switch (this.paramMainMenu)
case Constants.ZERO:
this.goToProductList();
break;
case Constants.ONE:
this.goToFragmentA();
break;
case Constants.TWO:
this.goToFragmentB();
break;
case Constants.THREE:
this.goToFragmentC();
break;




@Override
protected void handleAppLinkIntent(Uri appLinkData)
if(appLinkData.getQueryParameterNames().isEmpty())
String path = appLinkData.getPath();
switch (path)
case "/kfc/food/price/outofstock":
this.paramMainMenu = Constants.ONE;
break;
case "/food/price/qty":
this.paramMainMenu = Constants.THREE;
break;
case "/price/unbuyable":
this.paramMainMenu = Constants.TWO;
break;
case "/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/food/price":
this.paramMainMenu = Constants.ZERO;
break;
case "/a/food/item":
this.paramMainMenu = Constants.ZERO;
break;
case "/":
this.paramMainMenu = Constants.ZERO;
break;









java android android-fragments deep-linking applinks






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 5:52







Nadya Prabaningrum

















asked Nov 13 '18 at 4:20









Nadya PrabaningrumNadya Prabaningrum

412




412












  • Use NavigationDrawer, BottomNavigation or ViewPager.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:23












  • using NavigationDrawer @ZwalPyaeKyaw

    – Nadya Prabaningrum
    Nov 13 '18 at 4:25







  • 1





    You can use FragmentManager() to switch between Fragments.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:28











  • getSupportFragmentManager().beginTransaction(). replace(R.id.flContainer, new DemoFragment(), "SOMETAG"). commit(); // Now later we can lookup the fragment by tag DemoFragment fragmentDemo = (DemoFragment) getSupportFragmentManager().findFragmentByTag("SOMETAG"); like this. Here's the link to tutorial.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:33











  • I've use that, the function is the same with clickListener on NavigationDrawer menu. now the problem is when I call the function of switch fragment into handleIntent on Applink, there is no effect. I'm always goto fragment A.

    – Nadya Prabaningrum
    Nov 13 '18 at 4:35

















  • Use NavigationDrawer, BottomNavigation or ViewPager.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:23












  • using NavigationDrawer @ZwalPyaeKyaw

    – Nadya Prabaningrum
    Nov 13 '18 at 4:25







  • 1





    You can use FragmentManager() to switch between Fragments.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:28











  • getSupportFragmentManager().beginTransaction(). replace(R.id.flContainer, new DemoFragment(), "SOMETAG"). commit(); // Now later we can lookup the fragment by tag DemoFragment fragmentDemo = (DemoFragment) getSupportFragmentManager().findFragmentByTag("SOMETAG"); like this. Here's the link to tutorial.

    – Zwal Pyae Kyaw
    Nov 13 '18 at 4:33











  • I've use that, the function is the same with clickListener on NavigationDrawer menu. now the problem is when I call the function of switch fragment into handleIntent on Applink, there is no effect. I'm always goto fragment A.

    – Nadya Prabaningrum
    Nov 13 '18 at 4:35
















Use NavigationDrawer, BottomNavigation or ViewPager.

– Zwal Pyae Kyaw
Nov 13 '18 at 4:23






Use NavigationDrawer, BottomNavigation or ViewPager.

– Zwal Pyae Kyaw
Nov 13 '18 at 4:23














using NavigationDrawer @ZwalPyaeKyaw

– Nadya Prabaningrum
Nov 13 '18 at 4:25






using NavigationDrawer @ZwalPyaeKyaw

– Nadya Prabaningrum
Nov 13 '18 at 4:25





1




1





You can use FragmentManager() to switch between Fragments.

– Zwal Pyae Kyaw
Nov 13 '18 at 4:28





You can use FragmentManager() to switch between Fragments.

– Zwal Pyae Kyaw
Nov 13 '18 at 4:28













getSupportFragmentManager().beginTransaction(). replace(R.id.flContainer, new DemoFragment(), "SOMETAG"). commit(); // Now later we can lookup the fragment by tag DemoFragment fragmentDemo = (DemoFragment) getSupportFragmentManager().findFragmentByTag("SOMETAG"); like this. Here's the link to tutorial.

– Zwal Pyae Kyaw
Nov 13 '18 at 4:33





getSupportFragmentManager().beginTransaction(). replace(R.id.flContainer, new DemoFragment(), "SOMETAG"). commit(); // Now later we can lookup the fragment by tag DemoFragment fragmentDemo = (DemoFragment) getSupportFragmentManager().findFragmentByTag("SOMETAG"); like this. Here's the link to tutorial.

– Zwal Pyae Kyaw
Nov 13 '18 at 4:33













I've use that, the function is the same with clickListener on NavigationDrawer menu. now the problem is when I call the function of switch fragment into handleIntent on Applink, there is no effect. I'm always goto fragment A.

– Nadya Prabaningrum
Nov 13 '18 at 4:35





I've use that, the function is the same with clickListener on NavigationDrawer menu. now the problem is when I call the function of switch fragment into handleIntent on Applink, there is no effect. I'm always goto fragment A.

– Nadya Prabaningrum
Nov 13 '18 at 4:35












1 Answer
1






active

oldest

votes


















1














your URL should contains some key-values to determine the the fragment to be open
let us take a example :
Fragment-A is design to show list of offers
Fragment-B is design to show list of product



your URL contains a key that should show the "product".



you can segregate the fragment based on the key-value of deeplink



Example



your url is




"https://xyzcompany.com/myapp?open=products"



insinde MainActivity.class onCreate()




String key;
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
if (appLinkData != null)
key = appLinkData.getQueryParameter("open");


if(key == products)
//launch Fragment-B
else
//launch Fraagment-A






share|improve this answer























  • there is no key, just like " google.com/account "

    – Nadya Prabaningrum
    Nov 13 '18 at 4:38












  • I'm success when there is a key, I can't handle when there is no key :(

    – Nadya Prabaningrum
    Nov 13 '18 at 4:39











  • does the deeplink is only for Fragment-B or sometime it is applicable for fragment-A also ?

    – Chethan Kumar
    Nov 13 '18 at 4:42











  • impl to many fragment. therefore I make handleAppLink become a class

    – Nadya Prabaningrum
    Nov 13 '18 at 5:46










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273754%2fdeeplink-into-another-fragment-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














your URL should contains some key-values to determine the the fragment to be open
let us take a example :
Fragment-A is design to show list of offers
Fragment-B is design to show list of product



your URL contains a key that should show the "product".



you can segregate the fragment based on the key-value of deeplink



Example



your url is




"https://xyzcompany.com/myapp?open=products"



insinde MainActivity.class onCreate()




String key;
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
if (appLinkData != null)
key = appLinkData.getQueryParameter("open");


if(key == products)
//launch Fragment-B
else
//launch Fraagment-A






share|improve this answer























  • there is no key, just like " google.com/account "

    – Nadya Prabaningrum
    Nov 13 '18 at 4:38












  • I'm success when there is a key, I can't handle when there is no key :(

    – Nadya Prabaningrum
    Nov 13 '18 at 4:39











  • does the deeplink is only for Fragment-B or sometime it is applicable for fragment-A also ?

    – Chethan Kumar
    Nov 13 '18 at 4:42











  • impl to many fragment. therefore I make handleAppLink become a class

    – Nadya Prabaningrum
    Nov 13 '18 at 5:46















1














your URL should contains some key-values to determine the the fragment to be open
let us take a example :
Fragment-A is design to show list of offers
Fragment-B is design to show list of product



your URL contains a key that should show the "product".



you can segregate the fragment based on the key-value of deeplink



Example



your url is




"https://xyzcompany.com/myapp?open=products"



insinde MainActivity.class onCreate()




String key;
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
if (appLinkData != null)
key = appLinkData.getQueryParameter("open");


if(key == products)
//launch Fragment-B
else
//launch Fraagment-A






share|improve this answer























  • there is no key, just like " google.com/account "

    – Nadya Prabaningrum
    Nov 13 '18 at 4:38












  • I'm success when there is a key, I can't handle when there is no key :(

    – Nadya Prabaningrum
    Nov 13 '18 at 4:39











  • does the deeplink is only for Fragment-B or sometime it is applicable for fragment-A also ?

    – Chethan Kumar
    Nov 13 '18 at 4:42











  • impl to many fragment. therefore I make handleAppLink become a class

    – Nadya Prabaningrum
    Nov 13 '18 at 5:46













1












1








1







your URL should contains some key-values to determine the the fragment to be open
let us take a example :
Fragment-A is design to show list of offers
Fragment-B is design to show list of product



your URL contains a key that should show the "product".



you can segregate the fragment based on the key-value of deeplink



Example



your url is




"https://xyzcompany.com/myapp?open=products"



insinde MainActivity.class onCreate()




String key;
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
if (appLinkData != null)
key = appLinkData.getQueryParameter("open");


if(key == products)
//launch Fragment-B
else
//launch Fraagment-A






share|improve this answer













your URL should contains some key-values to determine the the fragment to be open
let us take a example :
Fragment-A is design to show list of offers
Fragment-B is design to show list of product



your URL contains a key that should show the "product".



you can segregate the fragment based on the key-value of deeplink



Example



your url is




"https://xyzcompany.com/myapp?open=products"



insinde MainActivity.class onCreate()




String key;
Intent appLinkIntent = getIntent();
String appLinkAction = appLinkIntent.getAction();
Uri appLinkData = appLinkIntent.getData();
if (appLinkData != null)
key = appLinkData.getQueryParameter("open");


if(key == products)
//launch Fragment-B
else
//launch Fraagment-A







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 4:33









Chethan KumarChethan Kumar

133110




133110












  • there is no key, just like " google.com/account "

    – Nadya Prabaningrum
    Nov 13 '18 at 4:38












  • I'm success when there is a key, I can't handle when there is no key :(

    – Nadya Prabaningrum
    Nov 13 '18 at 4:39











  • does the deeplink is only for Fragment-B or sometime it is applicable for fragment-A also ?

    – Chethan Kumar
    Nov 13 '18 at 4:42











  • impl to many fragment. therefore I make handleAppLink become a class

    – Nadya Prabaningrum
    Nov 13 '18 at 5:46

















  • there is no key, just like " google.com/account "

    – Nadya Prabaningrum
    Nov 13 '18 at 4:38












  • I'm success when there is a key, I can't handle when there is no key :(

    – Nadya Prabaningrum
    Nov 13 '18 at 4:39











  • does the deeplink is only for Fragment-B or sometime it is applicable for fragment-A also ?

    – Chethan Kumar
    Nov 13 '18 at 4:42











  • impl to many fragment. therefore I make handleAppLink become a class

    – Nadya Prabaningrum
    Nov 13 '18 at 5:46
















there is no key, just like " google.com/account "

– Nadya Prabaningrum
Nov 13 '18 at 4:38






there is no key, just like " google.com/account "

– Nadya Prabaningrum
Nov 13 '18 at 4:38














I'm success when there is a key, I can't handle when there is no key :(

– Nadya Prabaningrum
Nov 13 '18 at 4:39





I'm success when there is a key, I can't handle when there is no key :(

– Nadya Prabaningrum
Nov 13 '18 at 4:39













does the deeplink is only for Fragment-B or sometime it is applicable for fragment-A also ?

– Chethan Kumar
Nov 13 '18 at 4:42





does the deeplink is only for Fragment-B or sometime it is applicable for fragment-A also ?

– Chethan Kumar
Nov 13 '18 at 4:42













impl to many fragment. therefore I make handleAppLink become a class

– Nadya Prabaningrum
Nov 13 '18 at 5:46





impl to many fragment. therefore I make handleAppLink become a class

– Nadya Prabaningrum
Nov 13 '18 at 5:46

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53273754%2fdeeplink-into-another-fragment-android%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Use pre created SQLite database for Android project in kotlin

Darth Vader #20

Ondo