How do Deep Link into a fragment in an Android App. Is it possible?

So is it possible to deep link into a fragment? So my main activity launches different fragments depending on what the user clicks.

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

Any help would be helpful

Thanks.


You certainly can do this. You'll need to parse the intent in the activity and use the fragment manager to populate late the fragment you wish. Replace Action and Fragment with your own.

@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 just strings that should be unique for a given intent. They can be anything. Like:

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

链接地址: http://www.djcxy.com/p/32998.html

上一篇: Grails 3 Integration测试中没有transactionManager错误

下一篇: 如何在Android应用程序中将Deep Link链接到片段中。 可能吗?