android - 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.java
的node_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
extends
BridgeActivity
我没有找到一种方法来接收传入的意图,而不是使用onNewIntent()
. 请帮助我
当前行为
- 当应用程序在后台时,深层链接工作正常。
- 当用户杀死应用程序并单击链接时,应用程序进入前台但它卡住了。这是由于
onNewIntent()
调用的时间无限。
解决方案
推荐阅读
- linux - 如何引用 xargs {} 中保存的对象/字符串的基本名称
- vuejs3 - Vue JS 3 类绑定不适用
- python - 将任务添加到运行循环并运行直到完成
- github - Jenkinsfile - 如何访问其他 github 文件?
- terraform - 具有可变对象的 Terraform 条件动态块
- r - 如何修复R中的特殊字符?替换字符
- python - 启动 selenium chromedriver 时出现问题:引发错误
- r - R函数返回0,在函数外运行时相同函数内的代码返回正确值
- r - 修改数据框R中的案例顺序
- reactjs - 为什么 Material UI Card Header 中的这个按钮不做任何事情?