我想从FragmentA (RootFragment)转到FragmentB但我不想在 FragmentB 返回后重新创建 FragmentA 的视图。
我正在使用 Jetpack Navigation 在 Fragment 之间导航。
为了实现上述目标,我有一个像这样的片段 Fragment:
class RootFragment : DaggerFragment() {
private var viewToRestore: View? = null
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
return if (viewToRestore != null) {
viewToRestore!!
} else {
return inflater.inflate(R.layout.fragment_root, parent, false)
}
}
override fun onDestroyView() {
viewToRestore = this.view
super.onDestroyView()
}
override fun onDestroy() {
super.onDestroy()
}
}
Run Code Online (Sandbox Code Playgroud)
但是,一旦我到达具有属性viewToRestore 的Fragment B,FragmentA (RootFragment) 就会泄漏。 …
android memory-leaks android-fragments android-navigation leakcanary
我正在关注谷歌codelab的即时应用程序.将原始应用程序转换为baseFeature并添加另一个功能模块后,它将像应用程序一样运行,但将基于原始的baseFeature.
根据代码实验室的说法,我更改了buld.gradle文件并从功能模块(非基本模块)中删除了应用程序组件.当我尝试构建项目时,我得到了跟随错误.
Error:(4) duplicate attribute
Error:/home/adventure/Desktop/android-topeka/topekaapk/build/intermediates/manifests/full/debug/AndroidManifest.xml:4 duplicate attribute
Error:java.util.concurrent.ExecutionException: com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
Error:com.android.builder.internal.aapt.AaptException: AAPT2 link failed:
Error:Execution failed for task ':topekaapk:processDebugResources'.
> Failed to execute aapt
Run Code Online (Sandbox Code Playgroud) 所以我一直在使用Jetpack navigation,碎片的数量一直在增长。
我们可以按照本文档中的描述将不同导航图中的片段分开
然后我尝试将不同的导航图放在不同的文件中,因为这样感觉文件更有条理和可读性更强,但是当我尝试导航到不同的 nav_graph 文件时出现以下错误。
nav_graph_start.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph_start"
app:startDestination="@id/splashScreen"
tools:ignore="UnusedNavigation">
<fragment
android:id="@+id/splashScreen"
android:name="com.timetoface.android.splash.SplashFragment"
android:label="Login Fragment"
tools:layout="@layout/fragment_splash">
<action
android:id="@+id/action_splash_to_login"
app:destination="@id/nav_graph_auth"
/>
<action
android:id="@+id/action_splash_to_home"
app:destination="@id/nav_graph_home"
/>
</fragment>
</navigation>
Run Code Online (Sandbox Code Playgroud)
nav_graph_auth.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph_auth"
app:startDestination="@id/emailLoginScreen"
tools:ignore="UnusedNavigation">
................................
</navigation>
Run Code Online (Sandbox Code Playgroud)
nav_graph_home.xml
<navigation xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/nav_graph_home"
app:startDestination="@id/emailLoginScreen"
tools:ignore="UnusedNavigation">
................................
</navigation>
Run Code Online (Sandbox Code Playgroud)
从动作 com.app.android:id/action_splash_to_home 引用的导航目的地 com.app.android:id/nav_graph_home 对这个 NavController 来说是未知的
所以,
是否尚不支持多个导航图文件?
我是否错过了一些我应该改变的东西?
我在我的android应用程序中使用https://github.com/dlazaro66/QRCodeReaderView(QR码扫描程序)
我的主要权限如下:
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera" />
<uses-feature android:name="android.hardware.camera.autofocus"/>
Run Code Online (Sandbox Code Playgroud)
在Gradle中我有以下代码:
compileSdkVersion 23
buildToolsVersion "23.0.2"
defaultConfig {
applicationId "com.gurkhatech.schoolmanagement"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
}
Run Code Online (Sandbox Code Playgroud)
我已经用Java实现了代码:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_qr);
mQrCodeReaderView = (QRCodeReaderView)findViewById(R.id.qrdecoderview);
mQrCodeReaderView.setOnQRCodeReadListener(this);
}
@Override
public void onQRCodeRead(String text, PointF[] points) {
Toast.makeText(getApplicationContext(),text,Toast.LENGTH_LONG).show();
}
@Override
public void cameraNotFound() {
}
@Override
public void QRCodeNotFoundOnCamImage() {
}
@Override
protected void onResume() {
super.onResume();
mQrCodeReaderView.getCameraManager().startPreview();
}
@Override
protected void onPause() {
super.onPause(); …Run Code Online (Sandbox Code Playgroud) 有两种方法可以通过"string"过滤java中的realmResult
RealmResults data = realm.where(RasifalDTO.class).contains(keyString,valueString);
Run Code Online (Sandbox Code Playgroud)
但我想要做的是过滤结果与尊重整数所以我试过:
RealmResults data = realm.where(RasifalDTO.class).contains(keyString,vauleInt+"");
Run Code Online (Sandbox Code Playgroud)
但我得到:
java.lang.IllegalArgumentException: Field 'rasifalType': type mismatch. Was INTEGER, expected [STRING].
我们熟悉用于在java和其他编程语言中调用方法的流畅接口.例如:
Picasso.with(this).load(url).into(imageView);
Run Code Online (Sandbox Code Playgroud)
这可以通过setter方法实现所需类型的返回对象.
public Picasso with(Context context)
{
this.context = context;
return this;
}
public X load(String url)
{
this.url = url;
return this;
}
public Y load(ImageView imageView)
{
this.imageView = imageView;
return this;
}
Run Code Online (Sandbox Code Playgroud)
我试图用kotlin数据类做同样的事情,但遗憾的是我找不到一种方法来覆盖我可以返回该对象的新实例的setter方法.
任何关于可以做什么的想法,以便我可以调用流畅的接口或至少改变setter如何工作可能是这样的
data class CorruptOfficeAccount(.....){
override fun addCollectedFee(Long money) :CorruptOfficeAccount {
this.money = money/5
}
}
Run Code Online (Sandbox Code Playgroud)
这样我就可以打电话了
CorrutOfficeAccount(....).method1().addCollectedFee(20000).method3()
Run Code Online (Sandbox Code Playgroud) 我正在关注谷歌Codelabs的即时应用程序,我正在尝试创建topeka-ui(一个用于即时应用程序的UI功能模块).
它告诉我为该UI模块启用这样的数据绑定:
当我尝试在android块中启用数据绑定时,我在gradle构建期间得到以下错误.
Error:Currently, data binding does not work for non-base feature modules.
Please, move data binding code to the base feature module.
See https://issuetracker.google.com/63814741 for details
Run Code Online (Sandbox Code Playgroud)
我该如何解决?
我正在使用RxJava/Kotlin Observable#take()从列表中获取前50个项目.但是#take()运算符的行为并不像Rx docs那样.
在Rx docs中,#take()定义为:
"只发出一个Observable发出的前n个项目"
我有这样的功能:
我们可以看到pageSize论证是50
最初size的list是300
之后#take(50)应用于那个Observable和下一个断点我仍然得到完整的大小列表i.e. size = 300
但是just for the check,如果事情是错的调试器或观察到的,我想只需要其显示名中含有"9"的项目,但这次我得到的预期结果smaller list与9处于它们的#displayName field.
我相信RxJava/Kotlin's #take()运营商并不那么疯狂,而且只是我.
我必须计算字符串中不同字符字母的数量,因此在这种情况下,计数将为 - 3(d,k和s)。
鉴于以下情况String:
String input;
input = "223d323dk2388s";
count(input);
Run Code Online (Sandbox Code Playgroud)
我的代码:
public int count(String string) {
int count=0;
String character = string;
ArrayList<Character> distinct= new ArrayList<>();
for(int i=0;i<character.length();i++){
char temp = character.charAt(i);
int j=0;
for( j=0;j<distinct.size();j++){
if(temp!=distinct.get(j)){
break;
}
}
if(!(j==distinct.size())){
distinct.add(temp);
}
}
return distinct.size();
}
Run Code Online (Sandbox Code Playgroud)
输出:3
是否有任何本地库可以返回该字符串中存在的字符数?
android ×6
java ×4
kotlin ×3
character ×1
contains ×1
distinct ×1
leakcanary ×1
memory-leaks ×1
qr-code ×1
realm ×1
rx-android ×1
rx-java ×1
rx-kotlin ×1
string ×1