Ivann Ruiz
09/24/2020, 8:05 PM1)
Nima
09/25/2020, 3:35 AMColton Idle
09/25/2020, 4:13 AMcoroutinedispatcher
09/25/2020, 8:55 AMcoroutineDispatcher
by username, because I like scheduling stuff in my personal life and I use coroutines 😛
Usually I try to stay active in Stack Overflow, Reddit Androiddev, Kotlin channel. Also I love open source and try contributing if time.
Proffesionally I have been working as an Android developer for 2 years and 11 months 🙈 and I love what I do. Currently based in Munich.
See ya around 👋Klaus
09/25/2020, 10:05 AMGalou Minisini
09/25/2020, 2:31 PMjava.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/collections/CollectionsKt;
java.lang.NoClassDefFoundError: Failed resolution of: Lkotlin/ranges/RangesKt;
And I find myself adding a bunch of rules to my proguard files to make my tests pass when my app is working fine. Any idea what I am doing wrong? Am I missing something?Arief Hidayat
09/25/2020, 3:05 PMKen Maffei
09/25/2020, 10:46 PMDavid Ng
09/26/2020, 2:43 AMprivate val _status = MutableLiveData<Status>()
val status: LiveData<Status>
get = _status
fun getStatus(id: Int) {
viewModelScope.launch {
repository.getStatus(id) // This return Flow<Status>
.collect { _status = it}
}
}
And I use data binding on my layout
<TextView
android:text="@{viewModel.status}" />
The UI doesn't get updated to the latest value as the status come through from repository, the Main thread is being held up.
If I switch the coroutine to use Dispatcher.IO, I got "java.lang.IllegalStateException: Cannot invoke setValue on a background thread"
as the status need to be set on Main thread.
I've tried using BroadcastChannel
private val statusChannel = BroadcastChannel<Status>(Channel.CONFLATED)
val status = statusChannel.asFlow().asLiveData()
fun getStatus(id: Int) {
viewModelScope.launch(<http://Dispatcher.IO|Dispatcher.IO>) {
repository.getStatus(id) // This return Flow<Status>
.collect { statusChannel.offer(it) }
}
}
But the idea of converting the channel back to flow feels odd.
What's the best way to approach this?Florian
09/26/2020, 7:16 AMFlorian
09/26/2020, 9:52 AMonCreateOptionsMenu
)coroutinedispatcher
09/26/2020, 10:55 AMMark
09/27/2020, 4:57 AMViewModel
class, I get bizarre “error: cannot find symbol” compilation errors (in corresponding generated java class for ViewModel) where the only way forward is to do a clean build, and then everything compiles as expected. Is there some gradle setting I can tweak to avoid this?
Execution failed for task ':mymodule:kaptDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
> java.lang.reflect.InvocationTargetException (no error message)
Nikhil
09/27/2020, 9:55 AMbobby
09/27/2020, 10:08 AMAyden
09/27/2020, 12:45 PMAyden
09/27/2020, 1:24 PMinterface VoteRepository {
fun getVoteDetails(): MutableLiveData<ArrayList<Vote>>
}
val voteViewModelFactory = VoteViewModelFactory(// I need to pass the VoteRepository here)
Sam
09/28/2020, 4:24 AMAyden
09/28/2020, 3:57 PMLiveData
?
private fun getVoteData(): ArrayList<PieEntry> {
...
val viewModel = ViewModelProvider(this, voteViewModelFactory).get(VoteViewModel::class.java)
val liveData = viewModel.getVote()
liveData.observe(viewLifecycleOwner, { vote ->
vote.forEach {
votes.add(PieEntry(it.total.toFloat(), it.name))
}
})
return votes
}
private fun generateChart(binding: FragmentPieChartBinding, getVoteData: ArrayList<PieEntry>) {
...
// Run before livedata execute
Log.d("TEST", votes.toString())
...
// Render chart result
}
Saul Wiggin
09/28/2020, 6:32 PMAppExecutors.getInstance().diskIO().execute(new Runnable(){
@Override
public void run() {
appDatabase.UIDao().insertUI(UI);
}
});
but I’m getting an error`Attempt to invoke virtual method 'com.journaldev.firstandroidassignment.dao.UIDao com.journaldev.firstandroidassignment.database.AppDatabase.UIDao()' on a null object reference.` Any help would be much appreciatedChris Fillmore
09/28/2020, 7:01 PMVinod Rai
09/29/2020, 7:01 AM-keepattributes *Annotation*, InnerClasses
-dontnote kotlinx.serialization.SerializationKt
-keep,includedescriptorclasses class com.yourcompany.yourpackage.**$$serializer { *; } # <-- change package name to your app's
-keepclassmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's
*** Companion;
}
-keepclasseswithmembers class com.yourcompany.yourpackage.** { # <-- change package name to your app's
kotlinx.serialization.KSerializer serializer(...);
}
The package name is changed,.. getting exception in kotlinx.serialization 1.0.0-RC
Serializer for class 'e' is not found.
Mark the class as @Serializable or provide the serializer explicitly.
Data classes are in shared code.
Why progaurd configuration is not working with minify enabled. can anyone help what I am missing here?
GitHub
Kotlin/kotlinx.serialization
Kotlin multiplatform / multi-format serialization - Kotlin/kotlinx.serializationritesh
09/30/2020, 10:54 AMSaul Wiggin
09/30/2020, 10:57 AMJason A. Donenfeld
09/30/2020, 1:01 PMlifecycleScope.launch {
try {
// do stuff
delay(5000)
// do stuff
} catch (_: Throwable) {
requireContext()
}
}
When the Fragment is destroyed (by, e.g., the user pressing the back button), the Fragment's coroutine scope will be properly cancelled, as you'd expect. This in turn raises a CancellationException inside the scope. This exception is caught by our catch block, above. requireContext() is then called, and throws a new exception, because the context has already been destroyed.
It seems like destruction of the context and such is happening in the wrong order. What should be happening instead is that context and binding and other various members that Fragment has should be set to null only after coroutines have exited.
The example is contrived, but imagine something a bit more sophisticated, like:
lifecycleScope.launch {
try {
binding!!.config = getConfigAsync()
} catch (_: Throwable) {
binding!!.config = null
}
}
Or, even more innocent looking:
lifecycleScope.launch {
try {
// do something expensive
} catch (_: Throwable) {
Toast.make(ctx, getString(R.string.error_string), LONG).show()
}
}
That getString will crash too.
You might respond that CancellationException should always be handled differently in every try-catch block ever for all coroutines. Maybe you're right. But that's a lot of refactoring and weirdness. And it seems like this would be better solved by just fixing the race of lifecycle shutdown vs context detachment.
Does that seem reasonable?Arief Hidayat
10/01/2020, 6:46 AMDavid Ng
10/01/2020, 10:47 AMclass profileViewModel: ViewModel() {
val profileRepository: ProfileRepository
fun subscribeToProfile(id: Int) {
viewModelScope.launch {
profileRepository.subscribeToProfile(id)
}
}
}
My repository class
class ProfileRepository {
fun subscribeToProfile(id: Int) {
withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
..... // Does this get cancelled onCleared()?
}
}
}
It seems to me the function in repository class still running despite I've navigated away from Profile Fragment.
I've tried to debug on the view model and override the onCleared() function and call .cancel()
override fun onCleared() {
super.onCleared()
viewModelScope.cancel()
}
I was able to breakpoint in onCleared()
and execute the .cancel()
but it doesn't cancel the job in repository.
Am I missing any steps here?Slackbot
10/01/2020, 11:11 AMRobby
10/01/2020, 12:55 PMRobby
10/01/2020, 1:52 PMRobby
10/01/2020, 1:52 PMVampire
10/01/2020, 1:55 PMNumber
is superclass of both, Double
and Int
(as well as Long
, Short
, Float
and Byte
).
So if you have a Number
typed variable, you can assign any number to it.Robby
10/01/2020, 3:21 PM