小编Deb*_*jee的帖子

尽管在 onDestroyView 中将父视图设置为 null,但片段视图内存泄漏

我知道将片段事务添加到backstack,然后从该片段移动到另一个片段,reference of the previous fragment's view is still available并且只有在按下后退按钮时它才会被销毁。为了避免这种情况,I have set the view to null in onDestroyView但问题是,leakcanary still shows view is not null and the view reference is still available而记录视图却说它为空。

为什么会这样?另外,如果我错了或遗漏了什么,请纠正我。

片段类-


private var mView: View? = null
private lateinit var btnSignUp: Button

 override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        mView = inflater.inflate(R.layout.fragment_login, container, false)
        return mView
    }

 override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState) …
Run Code Online (Sandbox Code Playgroud)

android memory-leaks android-fragments android-studio leakcanary

6
推荐指数
1
解决办法
2964
查看次数

如何以角度形式执行和显示服务器验证错误

我是角度的新手。我正在尝试一些东西并被卡住了。在我的表单中,我想将服务器验证响应显示为来自 laravel rest api 的错误。但不知道如何在模板中存储和显示。我能够将它记录到控制台,但无法通过错误消息进一步移动。

回复有点像这样——

{
    "message": {
        "firstname":["The firstname field is required."],
        "lastname":["The lastname field is required."],
        "email":["The email field is required."],
        "password":["The password field is required."]
    }
}
Run Code Online (Sandbox Code Playgroud)

服务代码:

registerUser(user): Observable<any> {
    return this.http
      .post<any>(`${this.url}/register`, user)
      .pipe(map(res => res.message));
}
Run Code Online (Sandbox Code Playgroud)

组件类中的注册用户方法:

registerUser() {
    console.log(this.registrationForm.value);
    this.authService.registerUser(this.registrationForm.value).subscribe(
        res => console.log(res),
        err => console.log(err)
    );
}
Run Code Online (Sandbox Code Playgroud)

另外,如果我在任何地方出错,请纠正我,我应该如何纠正它

validation server-side-validation angular-validation angular

5
推荐指数
2
解决办法
1万
查看次数

Android Hilt 的 ViewModel 范围仅限于 Navgraph、Provider Factory 问题

我使用Hilt进行依赖注入,专门用于注入ViewModel。还想将ViewModel 范围限制为 NavGraph。为此,我们通过传递NavGraph来获取ViewModelStoreOwner,现在通过将导航图提供的存储实例传递给ViewModelProvider来创建ViewModel。我面临的问题是,因为我只传递store 实例来获取ViewModelProvider而没有任何Factory,因为Hilt将实现它,所以我收到构建错误has no Zero argument constructor。当看到源代码时,我发现由于我只提供存储实例作为参数而不提供工厂,因此会自动提供一个简单的工厂,并且由于提供的工厂没有参数,因此出现此错误。

怎么解决这个问题呢?

从源代码(ViewModelProvider.java)调用的方法-

     * Creates {@code ViewModelProvider}. This will create {@code ViewModels}
     * and retain them in a store of the given {@code ViewModelStoreOwner}.
     * <p>
     * This method will use the
     * {@link HasDefaultViewModelProviderFactory#getDefaultViewModelProviderFactory() default factory}
     * if the …
Run Code Online (Sandbox Code Playgroud)

android dependency-injection android-jetpack dagger-hilt

5
推荐指数
1
解决办法
4367
查看次数