Android:如何在收到Firebase动态链接后删除引用? [英] Android: How to remove the reference to a firebase dynamic link after receiving it?

查看:63
本文介绍了Android:如何在收到Firebase动态链接后删除引用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用中,我在主要活动中收到动态链接.当用户打开链接并启动应用程序并完成正确的操作时,此方法非常有用,但是在应用程序中检索到动态链接后,动态链接似乎仍然存在.

In my app, I receive dynamic links within my main activity. This works great when a user opens a link and it launches the app and completes the correct actions, but the dynamic links seems to be staying around after it's been retrieved in the app.

即使用户按下链接并使用FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent())在应用程序中将其检索,用户也可以关闭该应用程序并在以后重新打开它,并且getDynamicLink(getIntent())仍将返回链接和意图内的数据.

Even after the user has pressed the link and it's retrived in the app with FirebaseDynamicLinks.getInstance().getDynamicLink(getIntent()), the user could close the app and reopen it some time later and getDynamicLink(getIntent()) would still return the link and the data within the intent.

是否有一种方法可以丢弃链接&一旦在应用程序中被检索过它的数据?我只需要做setIntent(null)吗?

Is there a way to discard the link & its data once it's been retrieved once in the app? Do I just need to do setIntent(null)?

这是我的MainActivity

@Override
protected void onCreate(Bundle savedInstanceState) {
    setTheme(R.style.ButtonTheme);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    handleDynamicLink();
}

private void handleDynamicLink() {
    FirebaseDynamicLinks.getInstance()
            .getDynamicLink(getIntent())
            .addOnSuccessListener(this, pendingDynamicLinkData -> {
                // Get deep link from result (may be null if no link is found)
                Uri deepLink = null;
                if (pendingDynamicLinkData != null) {
                    deepLink = pendingDynamicLinkData.getLink();
                    if(deepLink!=null){
                        String gameId = deepLink.getQueryParameter("id");
                        Intent intent = new Intent(this, MultiplayerActivity.class);
                        intent.putExtra("gameId",gameId);
                        startMultiplayerActivity(intent);
                    }
                    Log.d(TAG, "handleDynamicLink: bundle: "+deepLink.getQueryParameter("id"));
                }
            }).addOnFailureListener(this, e -> Log.w(TAG, "getDynamicLink:onFailure", e));
}

推荐答案

从动态链接获取数据后,可以根据需要将数据发送到Activity. 然后处理这个.

after you get data from dynamic Link, you can send Data to Activity as you want. and then handle this.

处理数据后,如果要丢弃数据,请在活动"中使用此代码.

after handle Data, if you want to discard Data, use this code in Activity.

getActivity().getIntent().setData(null);

这篇关于Android:如何在收到Firebase动态链接后删除引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆