我要实现backpress行为,以便在您将backstack设为空时按回车时会提示确认弹出窗口,否则它将弹出堆栈中的下一个片段。
我正在尝试获取backstack计数,但是我总是从两个片段管理器中获得0
getSupportFragmentManager().getBackStackEntryCount();
getFragmentManager().getBackStackEntryCount();
Run Code Online (Sandbox Code Playgroud)
我猜它应该工作,因为我检查了片段导航器的google代码,并且通过规范的片段事务将其添加到了backstack中:
FragmentNavigator.java:
if (initialNavigation || isClearTask) {
backStackEffect = BACK_STACK_DESTINATION_ADDED;
} else if (isSingleTopReplacement) {
// Single Top means we only want one instance on the back stack
if (mBackStack.size() > 1) {
// If the Fragment to be replaced is on the FragmentManager's
// back stack, a simple replace() isn't enough so we
// remove it from the back stack and put our replacement
// on the back stack in its place
mFragmentManager.popBackStack();
ft.addToBackStack(Integer.toString(destId));
mIsPendingBackStackOperation …Run Code Online (Sandbox Code Playgroud) android android-architecture-components android-architecture-navigation
我正在使用导航控制器1.0.0alpha05,它的工作原理非常好,但是当我在活动结果之后执行导航操作时,我却在为这个可怕的错误而苦苦挣扎。
我有一个单一的活动/多个片段结构,特别是一个包含项目列表的片段,另一个具有用于添加新项目的形式的片段。
当我添加另一张没有任何图片的照片时,它正在工作,并返回带有项目列表的上一张照片,但是当我拍摄一些照片时,导航期间会出现异常。
原因:java.lang.IllegalArgumentException:此NavController未知导航目标XX
包含操作的表单片段的导航图:
<fragment
android:id="@+id/idFormFragment"
android:name="FormFragment"
android:label="FormFragment"
tools:layout="@layout/form_fragment">
<argument
android:name="idClient"
android:defaultValue="-1"
app:argType="integer" />
<argument
android:name="idServer"
app:argType="string" />
<action
android:id="@+id/actionFormToList"
app:destination="@id/idListFragment" />
</fragment>
Run Code Online (Sandbox Code Playgroud)
带安全参数的动作调用代码
FormFragmentDirections.ActionFormToList action = new FormFragmentDirections.ActionFormToList(sample.getIdJob());
Navigation.findNavController(getView()).navigate(action);
Run Code Online (Sandbox Code Playgroud)
谢谢你的时间
android android-architecture-components android-jetpack android-architecture-navigation
我在包括gson库时遇到了gradle错误无法解决的问题。
我已经在这里和这里检查过类似的问题,但是提出的解决方案都不适合我,我继续收到相同的错误。
我的build.gradle模块:
android {
compileSdkVersion 24
buildToolsVersion '25.0.0'
}
repositories {
mavenCentral()
}
dependencies {
compile 'com.google.code.gson:gson:2.8.0'
}
Run Code Online (Sandbox Code Playgroud)
build.gradle项目
buildscript {
repositories {
mavenCentral()
jcenter()
}
allprojects {
repositories {
mavenCentral()
jcenter()
}
Run Code Online (Sandbox Code Playgroud)
正如答案中所建议的,它应该是足够的jcenter存储库,因为它是mavenCentral的超集,所以我也尝试了不同版本的gson,添加了“ +”等,但没有任何效果。
在此先感谢大家:)
android ×3
android-architecture-components ×2
android-architecture-navigation ×2
compilation ×1
gradle ×1
gson ×1