首页 > 解决方案 > onNewIntent() 在深度链接-Ionic-Android 上多次调用

问题描述

我已经使用电容器创建了一个离子角度应用程序,并且需要实现深度链接。我已经实现了这一点,并且当应用程序处于后台时,深层链接工作正常。当用户滑动终止应用程序并单击链接打开时,问题就出现了。目前我发现的onNewIntent() 是当用户单击链接时多次调用。谁能指导我在这里缺少什么?

onNewIntent()被添加在MainActivity.java

@Override
protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    String appLinkAction = intent.getAction();
    Uri appLinkData = intent.getData();
    if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null){
        this.updateServerHostname(appLinkData.toString());
        // Added the falg to identify the incoming intents
        **this.init(null, new ArrayList<Class<? extends Plugin>>(), this.config,true);**
    }
}

这里的问题来自this.init(). 这个方法被写在一个文件中调用BridgeActivity.javanode_modules文件中Capacitor

protected void init(Bundle savedInstanceState, List<Class<? extends Plugin>> plugins, JSONObject config,Boolean appLinkData) {
this.initialPlugins = plugins;
this.config = config;
loadConfig(this.getApplicationContext(),this);

getApplication().setTheme(getResources().getIdentifier("AppTheme_NoActionBar", "style", getPackageName()));
setTheme(getResources().getIdentifier("AppTheme_NoActionBar", "style", getPackageName()));
setTheme(R.style.AppTheme_NoActionBar);
setContentView(R.layout.bridge_layout_main);

this.load(savedInstanceState,appLinkData);


}




protected void load(Bundle savedInstanceState,Boolean appLinkData) {
    Logger.debug("Starting BridgeActivity");

    webView = findViewById(R.id.webview);

    cordovaInterface = new MockCordovaInterfaceImpl(this);
    if (savedInstanceState != null) {
      cordovaInterface.restoreInstanceState(savedInstanceState);
    }

    mockWebView = new MockCordovaWebViewImpl(this.getApplicationContext());
    mockWebView.init(cordovaInterface, pluginEntries, preferences, webView);

    pluginManager = mockWebView.getPluginManager();
    cordovaInterface.onCordovaInit(pluginManager);
    bridge = new Bridge(this, webView, initialPlugins, cordovaInterface, pluginManager, preferences, this.config);
    Splash.showOnLaunch(this, bridge.getConfig());

    if (savedInstanceState != null) {
      bridge.restoreInstanceState(savedInstanceState);
    }
    this.keepRunning = preferences.getBoolean("KeepRunning", true);
   // invoke the intent only when the appLink is false  
        **this.onNewIntent(getIntent());**
  }

由于该行也onNewIntent()多次调用. this.onNewIntent(getIntent());MainActivity extendsBridgeActivity

我没有找到一种方法来接收传入的意图,而不是使用onNewIntent(). 请帮助我

当前行为

  1. 当应用程序在后台时,深层链接工作正常。
  2. 当用户杀死应用程序并单击链接时,应用程序进入前台但它卡住了。这是由于onNewIntent()调用的时间无限。

标签: androidionic4deep-linkingcapacitorandroid-deep-link

解决方案


推荐阅读