james
06/16/2022, 11:06 PMhfhbd
06/18/2022, 8:15 AM1.8
instead.
plugins {
kotlin("android") version "1.7.0"
id("com.android.application") version "7.2.1"
}
android {
kotlinOptions {
jvmTarget = "1.8"
}
}
tasks {
withType<org.jetbrains.kotlin.gradle.tasks.KotlinCompile> {
println(kotlinOptions.jvmTarget) // prints null
}
}
yousef shaaban
06/18/2022, 3:21 PMtransient
final
int
m = 50;
i want to map this line at kotlin Not use
companion object
Rahul Gill
06/19/2022, 3:10 AMktoClient(someHeaderValue: ()->String)= HttpClient{
...
defaultConfig{
header("headerKey", someHeaderValue())
}
}
Tin Tran
06/20/2022, 2:41 AMFatal Exception: java.lang.IllegalStateException: Not implemented
at androidx.work.CoroutineWorker.getForegroundInfo$suspendImpl(CoroutineWorker.java:100)
at androidx.work.CoroutineWorker.getForegroundInfo(CoroutineWorker.java:6)
at androidx.work.CoroutineWorker$getForegroundInfoAsync$1.invokeSuspend(CoroutineWorker.kt:134)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.java:571)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:678)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:665)
My work manager dependency is
implementation 'androidx.hilt:hilt-work:1.0.0'
kapt 'androidx.hilt:hilt-compiler:1.0.0'
implementation "androidx.work:work-runtime-ktx:2.7.1"
Tim Malseed
06/20/2022, 4:32 AMconnectedDebugAndroidTest
task? We can attach a custom Junit RunListener
via gradle testInstrumentationRunnerArguments
- but this passes progress back to the app’s process itself, rather than our local machine.Elnur Jeksenov
06/20/2022, 8:53 AMwindow.setFlags(WindowManager.LayoutParams.FLAG_SECURE, WindowManager.LayoutParams.FLAG_SECURE)
is there any other solution?Tim Malseed
06/20/2022, 1:30 PMkotlinforandroid
06/21/2022, 11:50 AMandroidx.work.Worker
. However, reading the value requires me to register a callback. How do I make my worker wait for the callback to return once without using a busy-loop? Is there a builtin way? JobService
has a dedicated finishJob
method that one could call from the callback. androidx.work
seems to not have this
class MyWorker(sm: SensorManager, sensor: Sensor, context: Context, params: WorkerParameter): Worker(context, params) {
private flag: Boolean = false
override fun doWork(): Result {
sm.registerListener(object : SensorEventListener {
override fun onSensorEvent(e: SensorEvent) {
flag = true
// use value...
}
}, sensor, TIMEFRAME_FASTEST)
while (!flag) { }
return Result.success()
}
}
samp
06/21/2022, 9:14 PMSatyam G
06/22/2022, 2:08 PMappUpdateManager.startUpdateFlowForResult(
info,
AppUpdateType.IMMEDIATE,
parentActivity,
MY_REQUEST_CODE
)
Which triggers the Immediate flow. If you observe here we are passing here the MY_REQUEST_CODE while triggering Update.
Once the update is Finished, Cancel we get the callback in OnActivityResult based on that we can take decisions. But we already know onActivityResult is deprecated now and it is recommended to use the Activity Result Api which has a code like
var resultLauncher =
registerForActivityResult(ActivityResultContracts.StartActivityForResult()) { result ->
if (result.resultCode == Activity.RESULT_OK) {
// There are no request codes
val data: Intent? = result.data
inAppUpdate?.let {
inAppUpdate?.onActivityResult(result.resultCode, data)
}
} else if (result.resultCode == AppCompatActivity.RESULT_CANCELED) {
finish()
}
}
But How to get the request code in this case ???
Can anyone help here ?Erwin Pandawa5
06/23/2022, 1:34 AMSven Obser
06/23/2022, 3:09 PMkotlin.random.Random
produces the same “random” values with each app start on Android. 😨 Is this expected behavior?
Log.e { "java.util.Random().nextInt(): ${java.util.Random().nextInt()}" }
Log.e { "kotlin.random.Random.nextInt(): ${kotlin.random.Random.nextInt()}" }
Output:
java.util.Random().nextInt(): -1853486751
kotlin.random.Random.nextInt(): -351317653
java.util.Random().nextInt(): 1794921748
kotlin.random.Random.nextInt(): -351317653
java.util.Random().nextInt(): 1849140367
kotlin.random.Random.nextInt(): -351317653
Vivek Modi
06/24/2022, 9:06 AMFor example 1
val string = "Birth Control"
val searchText = "n"
Output
["Birth Co", "trol"]
For example 2
val string = "Bladder Infection"
val searchText = "i"
Actual Output
["Bladder ", "nfect", "on"]
Expect Output
["Bladder ", "nfection"]
I tried some code but example 1
is working fine but example 2
is not because I only want to split first occurrence.
val splitList = title?.split(searchText, ignoreCase = true)?.toMutableList()
splitList?.remove(searchText)
Can someone guide me how to solve this idiomatic way. ThanksNurbanu Kahraman
06/24/2022, 10:51 AMdavidbritish
06/24/2022, 9:34 PMrkeazor
06/25/2022, 2:20 AMAmrJyniat
06/25/2022, 5:01 AMvar property: String? = null
.......
propertyFlow.collect{
property = it
}
.......
textView.text = property // reflect this value when its get ready
Something like that, any idea?brookmg
06/25/2022, 9:18 AMHannan Shaikh
06/26/2022, 12:34 PMdazza5000
06/27/2022, 6:22 PMColton Idle
06/28/2022, 2:21 AMMahesh Kavathiya
06/28/2022, 5:32 AMAli
06/29/2022, 11:43 AMmutableListOf(listOf(1,2,3,4,5), listOf(6,7,8,9,10))
I need this modified result but keeping original list as it is.
[[1,2], [6,7,8,9,10]]
Aldup
06/29/2022, 11:37 PMMichael Bichlmeier
06/30/2022, 8:28 AMRohan Maity
06/30/2022, 9:53 AMMjahangiry75
06/30/2022, 11:02 AMretrofit
and room?
Katarzyna
06/30/2022, 11:26 AMAmrJyniat
06/30/2022, 1:18 PMSharedFlow
when the first collect got exception?
like I expose a Flow
from repo to VM then convert it to SharedFlow
by shareIn()
then collect this SharedFlow from the fragment, now I got an exception while collecting the SharedFlow, so how to retry/recollect it again?AmrJyniat
06/30/2022, 1:18 PMSharedFlow
when the first collect got exception?
like I expose a Flow
from repo to VM then convert it to SharedFlow
by shareIn()
then collect this SharedFlow from the fragment, now I got an exception while collecting the SharedFlow, so how to retry/recollect it again?gildor
07/05/2022, 4:14 AMretry
for this:
https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/retry.htmlretry
AmrJyniat
07/05/2022, 7:07 AMflow.retryWhen { cause, attempt ->
attempt < 3
}
But I have a button for retrying the API call when failed and, I couldn't handle the retry mechanism when the click event occurred.gildor
07/05/2022, 7:10 AMAmrJyniat
07/05/2022, 7:20 AMval flow: Flow<Result<T>> = repo.getData()
And collect the flow in the fragment, now the retry button appears when the result
failed, I searched for an elegant/clean way to recollect the flow on the click event, therefore, the API called again but I didn't found.
I ended up with something like that:
private val _sponsors = Channel<Unit>()
val sponsors = _sponsors.receiveAsFlow().flatMapLatest {
repository.loadSponsors()
}.myShareIn(viewModelScope, replay = 1)
fun loadSponsors() = viewModelScope.launch {
_sponsors.send(Unit)
}
init { loadSponsors() }
In this case, just call `loadSponsors()`fun when the retry button clicked, what do you think?gildor
07/05/2022, 9:33 AMval sponsors = _sponsors.receiveAsFlow().flatMapLatest {
return runCatching {
repository.loadSponsors())
}
}.myShareIn(viewModelScope, replay = 1)
AmrJyniat
07/05/2022, 9:40 AMgildor
07/05/2022, 9:47 AMAmrJyniat
07/05/2022, 10:10 AMsponsors
val is a flow containing custom Result class Result<T>
, so when collecting it in the fragment I'm just checking if the result failed or not, therefore, I don't need any processing in the VM like runCathing{}
because the catch applied already in the repo layer.gildor
07/05/2022, 12:51 PMAmrJyniat
07/05/2022, 12:58 PMgildor
07/05/2022, 1:51 PMAmrJyniat
07/05/2022, 2:03 PMgildor
07/05/2022, 3:09 PM