Deeplink into another fragment [ANDROID](深度链接到另一个片段[Android])
本文介绍了深度链接到另一个片段[Android]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
活动和片段的结构如下:
使用NavigationDrayer。
MainActivity有一个碎片容器,一个容器中应该有多个碎片。应用启动后,默认分片为分片A使用片段B实现深度链接到MainActivity,以及如何将片段从片段A(默认)更改为片段B(目标)。
任何帮助都会有帮助:) 谢谢
即 类句柄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)
执行函数
@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;
}
}
}
URL
您的推荐答案应包含一些键值,以确定要打开的片段 让我们举一个例子: 片段A旨在显示报价列表 片段B旨在显示产品列表
您的URL包含应显示"产品"的密钥。
您可以根据deeplink的键值进行分片
示例
您的URL是
"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
}
这篇关于深度链接到另一个片段[Android]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:深度链接到另一个片段[Android]


猜你喜欢
- GC_FOR_ALLOC 是否更“严重"?在调查内存使用情况时? 2022-01-01
- 获取数字的最后一位 2022-01-01
- 如何使 JFrame 背景和 JPanel 透明且仅显示图像 2022-01-01
- 未找到/usr/local/lib 中的库 2022-01-01
- 如何指定 CORS 的响应标头? 2022-01-01
- 在 Java 中,如何将 String 转换为 char 或将 char 转换 2022-01-01
- 转换 ldap 日期 2022-01-01
- Eclipse 的最佳 XML 编辑器 2022-01-01
- 将 Java Swing 桌面应用程序国际化的最佳实践是什么? 2022-01-01
- java.lang.IllegalStateException:Bean 名称“类别"的 BindingResult 和普通目标对象都不能用作请求属性 2022-01-01