6,863 questions
888
votes
23
answers
565k
views
Unfortunately MyApp has stopped. How can I solve this?
I am developing an application, and everytime I run it, I get the message:
Unfortunately, MyApp has stopped.
What can I do to solve this?
About this question - obviously inspired by What is a stack ...
33
votes
4
answers
10k
views
Why does my function that calls an API or launches a coroutine return an empty or null value?
(Disclaimer: There are a ton of questions which arise from people asking about data being null/incorrect when using asynchronous operations through requests such as facebook,firebase, etc. My ...
578
votes
19
answers
571k
views
How to launch an Activity from another Application in Android
I want to launch an installed package from my Android application. I assume that it is possible using intents, but I didn't find a way of doing it. Is there a link, where to find the information?
398
votes
10
answers
379k
views
Alarm Manager Example
I want to implement a schedule function in my project. So I Googled for an Alarm manager program but I can`t find any examples.
Can anyone help me with a basic alarm manager program?
14
votes
4
answers
13k
views
Android Kotlin: Getting a FileNotFoundException with filename chosen from file picker?
I'm working on an Android application where one of the features is to let the user choose a file to open (I'm wanting to open a plain text .txt file). I've worked on Android apps before with Java, ...
231
votes
11
answers
280k
views
How to allow all Network connection types HTTP and HTTPS in Android (9) Pie?
From Android 9 Pie now, requests without encryption will never work. And by default, the System will expect you to use TLS by default.You can read this feature here So if you only make requests via ...
16
votes
3
answers
14k
views
How to return a list from Firestore database as a result of a function in Kotlin?
I'm building an app for a friend and I use Firestore. What I want is to display a list of favorite places but for some reason, the list is always empty.
I cannot get the data from Firestore. This is ...
249
votes
19
answers
239k
views
The AsyncTask API is deprecated in Android 11. What are the alternatives?
Google is deprecating Android AsyncTask API in Android 11 and suggesting to use java.util.concurrent instead. you can check out the commit here
*
* @deprecated Use the standard <code>java.util....
2
votes
2
answers
4k
views
Kotlin DateTimeParseException
Getting date from https://api.spacexdata.com/v3/launches
This date have format: 2006-03-25T10:30:00+12:00.
I want convert it to "dd, mm, yyyy", but always getting error:
"java.time....
615
votes
15
answers
432k
views
How to make an Android device vibrate? with different frequency?
I wrote an Android application. Now, I want to make the device vibrate when a certain action occurs. How can I do this?
550
votes
8
answers
440k
views
How to convert a Kotlin source file to a Java source file
I have a Kotlin source file, but I want to translate it to Java.
How can I convert Kotlin to Java source?
208
votes
4
answers
100k
views
In Kotlin, what is the idiomatic way to deal with nullable values, referencing or converting them
If I have a nullable type Xyz?, I want to reference it or convert it to a non-nullable type Xyz. What is the idiomatic way of doing so in Kotlin?
For example, this code is in error:
val something: ...
406
votes
45
answers
669k
views
Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15
In Stripe, my client wants email and cardholder name, but the Stripe payment UI doesn't provide that option in com.stripe.android.view.CardMultilineWidget. I wanted to give it a try with the latest ...
238
votes
17
answers
556k
views
How to parse JSON in Kotlin?
I'm receiving a quite deep JSON object string from a service which I must parse to a JSON object and then map it to classes.
How can I transform a JSON string to object in Kotlin?
After that the ...
257
votes
39
answers
288k
views
android:exported needs to be explicitly specified for <activity>. Apps targeting Android 12 and higher are required to specify
After upgrading to android 12, the application is not compiling. It shows
"Manifest merger failed with multiple errors, see logs"
Error showing in Merged manifest:
Merging Errors:
Error: ...
3
votes
1
answer
2k
views
getInstance() doesn't work with other location than us-central1 in Realtime Database
I am trying to save user credentials to Firebase Realtime Database. However, when I execute the program, the DB does not update. I have configured the Firebase setup correctly as Authentication and ...
92
votes
10
answers
173k
views
Android: How to Enable/Disable Wifi or Internet Connection Programmatically
Using the Connectivity Manager Class we can get access to either wifi or Internet Network:
ConnectivityManager connec = (ConnectivityManager)getSystemService(Context.CONNECTIVITY_SERVICE);
// ARE WE ...
120
votes
6
answers
262k
views
How to do bulk (multi row) inserts with JpaRepository?
When calling the saveAll method of my JpaRepository with a long List<Entity> from the service layer, trace logging of Hibernate shows single SQL statements being issued per entity.
Can I force ...
18
votes
1
answer
10k
views
Jetpack Compose Scoped/Smart Recomposition
I'm doing experiments to comprehend recomposition and smart recomposition and made a sample
Sorry for the colors, they are generated with Random.nextIn() to observe recomposition visually, setting ...
238
votes
24
answers
269k
views
Android Room - simple select query - Cannot access database on the main thread
I am trying a sample with Room Persistence Library.
I created an Entity:
@Entity
public class Agent {
@PrimaryKey
public String guid;
public String name;
public String email;
...
13
votes
2
answers
9k
views
Singleton object becomes null after app is resumed
For my Android project, I need global singleton Cache object to access data about a user through the app.
A problem occurs when an app goes into the background and after some time of using other ...
434
votes
13
answers
195k
views
Smart cast to 'Type' is impossible, because 'variable' is a mutable property that could have been changed by this time
And the Kotlin newbie asks, "why won't the following code compile?":
var left: Node? = null
fun show() {
if (left != null) {
queue.add(left) // ERROR HERE
}
}
Smart cast ...
6
votes
2
answers
3k
views
Updating Paging 3 alpha to stable cause indexing issue Android
Hey I am using Paging 3 library with ViewPager 2. In which it loads unlimited data.
implementation "androidx.paging:paging-runtime-ktx:3.0.0-alpha07"
DataSource.kt
package com.example....
169
votes
29
answers
91k
views
ListAdapter not updating item in RecyclerView
I'm using the new support library ListAdapter. Here's my code for the adapter
class ArtistsAdapter : ListAdapter<Artist, ArtistsAdapter.ViewHolder>(ArtistsDiff()) {
override fun ...
6
votes
2
answers
11k
views
Why do I get "unresolved reference" error for my view's name/ID when I type it in Kotlin?
I am following a tutorial exactly. I gave the view a name in the layout XML file under android:id. When I type that name in Kotlin, it is highlighted in red and there is an "unresolved reference&...
104
votes
15
answers
171k
views
How can I convert a part of Java source file to Kotlin?
In my Kotlin project, I have some parts of Java code that I want to convert to Kotlin. The menu item that converts the Java file to Kotlin is disabled because it's not a whole file I want to convert.
...
269
votes
13
answers
163k
views
startForeground fail after upgrade to Android 8.1
After upgrading my phone to 8.1 Developer Preview my background service no longer starts up properly.
In my long-running service I've implemented a startForeground method to start the ongoing ...
409
votes
30
answers
217k
views
What is the difference between var and val in Kotlin?
What is the difference between var and val in Kotlin?
I have gone through this link:
KotlinLang: Properties and Fields
As stated on this link:
The full syntax of a read-only property declaration ...
371
votes
36
answers
1.2m
views
Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0
I've got a gradle FAILURE:
..."Deprecated Gradle features were used in this build, making it incompatible with Gradle 5.0."
Case description:
Attached to the project codebase the next libs:
APP/build....
369
votes
5
answers
169k
views
Difference between List and Array types in Kotlin
What is the difference between List and Array types?
It seems can make same operations with them (loops, filter expression, etc..), is there any difference in behavior or usage?
val names1 = listOf("...
130
votes
8
answers
36k
views
What is a "receiver" in Kotlin?
How is it related to extension functions? Why is with a function, not a keyword?
There appears to be no explicit documentation for this topic, only the assumption of knowledge in reference to ...
12
votes
1
answer
3k
views
How to improve image segmentation using the watershed?
I am developing an application to detect the lesion area, for this I am using the grabcut to detect the ROI and remove the background from the image. However in some images it is not working well. He ...
455
votes
4
answers
165k
views
How does the reified keyword in Kotlin work?
I'm trying to understand the purpose of the reified keyword. Apparently, it's allowing us to do reflection on generics.
However, when I leave it out, it works just as fine. When does this make an ...
383
votes
20
answers
197k
views
What do I use now that Handler() is deprecated?
How do I fix the deprecation warning in this code? Alternatively, are there any other options for doing this?
Handler().postDelayed({
context?.let {
//code
}
}, 3000)
452
votes
70
answers
305k
views
Duplicate class in Kotlin Android
I kept on getting an error that there is a duplicate error in classes.
This is what I have under org.jetbrains.kotlin folder
.idea/libraries
It seems like the problem is because there is two different ...
83
votes
12
answers
90k
views
JCenter deprecation; impact on Gradle and Android
Should I be worried about JCenter being deprecated?
Why should I migrate my libraries from JCenter to other Maven repositories?
Can I continue to use jcenter() in my Gradle build script?
11
votes
1
answer
7k
views
How to get exact size without recomposition?
I need size of my composable to draw dynamic lines but I don't want to get size by:
var size by remember { mutableStateOf(IntSize.Zero) }
Modifier.onSizeChanged{size = it}
or
Modifier....
281
votes
45
answers
597k
views
Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details
Error:Execution failed for task ':app:compileDebugKotlin'. > Compilation error. See log for more details
build:gradle(Module:app)
buildscript {
repositories {
maven {
url '...
122
votes
10
answers
84k
views
How to invoke external command from within Kotlin code?
I want to invoke an external command from Kotlin code.
In C/Perl, I would use the system() function.
In Python, I would use the subprocess module.
In Go, I would use os/exec, and etc.
But how do I ...
88
votes
3
answers
20k
views
Kotlin Bytecode - How to analyze in IntelliJ IDEA?
I want to see the compiled bytecode so I can learn more about how it works under the cover. I'm using IntelliJ IDEA 15 but can't find a way to see the bytecode. What am I missing?
894
votes
33
answers
526k
views
Kotlin Ternary Conditional Operator
What is the equivalent of this expression in Kotlin?
a ? b : c
This is not valid code in Kotlin.
289
votes
2
answers
484k
views
How can I generate random number in specific range in Android? [duplicate]
I want to generate random number in a specific range. (Ex. Range Between 65 to 80)
I try as per below code, but it is not very use full. It also returns the value greater then max. value(greater then ...
279
votes
43
answers
458k
views
"Module was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.16"
The following error occurs when I tried to build the app:
C:/Users/Lenovo/.gradle/caches/transforms-2/files-2.1/32f0bb3e96b47cf79ece6482359b6ad2/jetified-kotlin-stdlib-jdk7-1.5.0.jar!/META-INF/kotlin-...
3
votes
4
answers
2k
views
Unresolved reference - activity does not recognize synthetic imports in android studio v4
last night I noticed I'm not able to change the attributes of elements in the layout from my main activity
so I built a new project and I had the same problem there too.
I could not find out what was ...
372
votes
15
answers
273k
views
Extend data class in Kotlin
Data classes seem to be the replacement to the old-fashioned POJOs in Java. It is quite expectable that these classes would allow for inheritance, but I can see no convenient way to extend a data ...
299
votes
8
answers
227k
views
How to create empty constructor for data class in Kotlin Android
I have 10+ variables declared in Kotlin data class, and I would like to create an empty constructor for it like how we typically do in Java.
Data class:
data class Activity(
var updated_on: String,...
233
votes
7
answers
72k
views
Single exclamation mark in Kotlin
What does a single exclamation mark mean in Kotlin? I've seen it a few times especially when using Java APIs. But I couldn't find it in the documentation nor on StackOverflow.
100
votes
23
answers
185k
views
RecyclerView itemClickListener in Kotlin
I'm writing my first app in Kotlin after 3 years of experience with Android.
Just confused as to how to utilize itemClickListener with a RecyclerView in Kotlin.
I have tried the trait (edit: now ...
413
votes
63
answers
612k
views
A failure occurred while executing org.jetbrains.kotlin.gradle.internal.KaptExecution
All of sudden I start getting this error, and I am not getting idea why if anyone just let me know where this error is, will be enough helpful. As much I am able to get is this because of new update ...
332
votes
11
answers
273k
views
What does a suspend function mean in Kotlin coroutines?
I'm reading Kotlin coroutines and know that it is based on suspend functions. But what does suspend mean?
Can a coroutine or a function get suspended?
From https://kotlinlang.org/docs/reference/...