简体   繁体   中英

Android - How to recreate Hilt?

In my app, user can sign in with multiple accounts. With each session, user's data is difference. I use single activity.

So, how to recreate Hilt after user signed in for reload Use case, Repository, Data source? Or best practice using Hilt with multiple account?

You can look for dependency scopes for Hilt. For your case, just use ActivityRetainedComponent on your AppModule. Add @ActivityRetainedScoped on your constructor class instead of singleton.

With this way, user's data create when activity created, and destroy when activity destroy.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM