Niraj Tiwari
02/26/2021, 7:11 AMchrisxinyue
02/26/2021, 8:42 AMonCommit{}
builder being detached https://stackoverflow.com/questions/66382326/has-android-jetpack-compose-beta-detached-builder-of-oncommit ?Travis Griggs
02/26/2021, 8:51 PMsupportFragmentManager.commit {
...
}
When I see this pattern, I think "trailing closure syntax". On closer examination, I realized that this
in said closure-esque body wasn't what I thought it was, so I went and found the method signature for FragmentManager.commit...
FragmentManager.commit(allowStateLoss: Boolean = false, body: FragmentTransaction.() -> Unit
I know that () -> Unit is a nullary closure, but what does it mean when I see the above? ClassName.() -> Unit?Slackbot
02/27/2021, 3:56 AMKulwinder Singh
02/28/2021, 7:34 AMmelatonina
02/28/2021, 7:28 PMMadalin Valceleanu
03/01/2021, 8:13 AMsingle-activity architecture
, using the Navigation component to manage fragment operations.
• Android architecture components
, part of Android Jetpack give to project a robust design, testable and maintainable.
• Pattern Model-View-ViewModel
(MVVM) facilitating separation of development of the graphical user interface.
• S.O.L.I.D
design principles intended to make software designs more understandable, flexible and maintainable.
• Modular app architecture
allows being developed features in isolation, independently from other features.
Project link: https://github.com/VMadalin/android-modular-architectureValtteri Puonti
03/01/2021, 12:40 PMactivityResultRegistry
in Activity tests? The docs have a clear example of testing Fragments, but that approach is not valid for Activities.Chris Fillmore
03/02/2021, 3:11 PMtherealbluepandabear
03/03/2021, 1:29 AMCaio Costa
03/03/2021, 2:44 AM// Using an Interface
interface ABC {
fun doIt()
}
private fun doIt() {
val doItListener = object : ABC {
override fun doIt() {
println("Do it!")
}
}
//Passing the Interface reference
Main(doItListener)
}
// Class which the instruction will be executed in(Interface reference)
class Main(listener: ABC) {
init {
listener.doIt()
}
}
----------------------------------------------------
// Using Method reference
private fun doIt2() {
println("Do it!")
}
private fun callDoIt2() {
//Passing Method reference
Main(::doIt2)
}
// Class which the instruction will be executed in(Method reference)
class Main(task: () -> Unit) {
init {
task()
}
}
----------------------------------------------------
//Running
fun main() {
doIt()
callDoIt2()
}
I ran both ways and both worked. But in my real scenario, the "Main" classes are Adapters and both doIt() and doIt2() would be instructions executed when users clicked an item of a list. Both examples would be triggered by such action individually.
But my main question is: Does passing a reference of a method located at an Activity actually take with it any kind of information of such Activity which in this case is where it's located at? What do you think is the best approach in this case: A listener created from an Interface or putting all instructions inside a method and then passing its reference to an Adapter or whatever class it is. I'd like to hear from you guys. Thanks in advance.Nraghuramireddy
03/03/2021, 8:31 AMnote8g2018
03/03/2021, 10:08 AMIssa
03/03/2021, 10:14 AMimport kotlin.reflect.KClass
fun main() {
doSomething(B::class, C::class)
}
fun <T : A> doSomething(vararg dialogClasses: KClass<T>) {
// no-op
}
open class A
class B : A()
class C : A()
the compiler complains about the second argument of doSomething()
function even if it is a sub-type of A
. Is there any reason for this complaint?
How can this issue can be solved?Johan
03/03/2021, 10:31 AMDeepak Gahlot
03/04/2021, 4:24 AMAnshulupadhyay03
03/04/2021, 3:29 PMSudhir Singh Khanger
03/04/2021, 3:37 PM``` CoroutineScope(coroutineContext).launch {
val saveProfileWork = OneTimeWorkRequestBuilder<SaveProfileWorker>()
.setInputData(
workDataOf(
"IMAGE_URI" to "http://..."
)
)
.build()
val request = WorkManager.getInstance(context).beginWith(saveProfileWork).enqueue().await()
// post success
return@launch
}
```
1. As far as my understanding goes launch starts a coroutine and await() awaits the result from another builder aynch(). This means I will be creating a coroutine inside a coroutine. Outer would be part of my network layer and inner one would be work manager's. I am not sure what should be done here. This also sounds like I might have issue handling exception.
2. How do I get success value from await call? If it asynchronous then return will end the outer launch coroutine.allan.conda
03/04/2021, 4:02 PMpascalchidi
03/04/2021, 9:56 PMpascalchidi
03/04/2021, 9:57 PMAnshulupadhyay03
03/05/2021, 11:05 AMMartyna Maron
03/05/2021, 4:25 PMonResume
of my main fragment, I’ve got code like this (further down the chain, I don’t call this directly like this in onResume
):
suspend fun onSessionStart() = withContext(Dispatcher.javascript) {
for(feature in featuresList) {
feature.setUpSynchronously()
myActivity.lifecycleScope.launch(Dispatcher.javascript) {
feature.setUpAsync()
}
}
}
Right after I call this method above, I call this:
suspend fun start() = withContext(Dispatcher.javascript) {
//...
}
Note that setUpAsync()
may call a method which switches to Dispatcher.network
, but doesn’t launch a new coroutine.
My problem is that on a fresh app launch, this code runs fine, but when I trigger onSessionStart
again, when the app is still alive, I never get to start()
and the app stalls. I can see by the logs that all of the setUpAsync()
calls finish, but they don’t seem to return 🤷♀️🏻
Removing the context when launching the async set up, seems to fix the problem:
myActivity.lifecycleScope.launch {
feature.setUpAsync()
}
But I don’t understand why, any idea?Jorge Andrés Díaz Naranjo
03/05/2021, 4:29 PMParcelable
in a non-Android module? :bugdroid: I have modules with domain classes, but I need to pass them through bundleGene Cahill
03/05/2021, 4:43 PMRemy Benza
03/05/2021, 5:30 PMPatrick Yin
03/06/2021, 12:24 AMmelatonina
03/07/2021, 6:07 PMObservableProperty
with `StateFlow`/`MutableStateFlow`. How can I perform the equivalent of the select
operation with StateFlow
?
The best that came to my mind is something similar to this function:
fun <T, U> CoroutineScope.selectFlow(
stateFlow: StateFlow<T>,
op: (T) -> StateFlow<U>
): StateFlow<U> {
// We can't create a MutableStateFlow without an initial value
val mutableStateFlow = MutableStateFlow(op(stateFlow.value).value)
var job: Job? = null
launch {
stateFlow.collect {
job?.cancel()
job = launch {
op(stateFlow.value).collect {
mutableStateFlow.emit(it)
}
}
}
}
return mutableStateFlow
}
I don't know the StateFlow API very well. Is there a better way?Ezra En Yong
03/08/2021, 3:36 AMAkinde Kolawole
03/08/2021, 11:12 AMAkinde Kolawole
03/08/2021, 11:12 AMReprator
08/29/2021, 9:48 AM