Found 1631 Articles for Android

What are the Signs of a Malware Attack on an Android Phone?

Pranav Bhardwaj
Updated on 02-Jun-2022 09:47:39

351 Views

Internet browsing offers several outstanding features for the user, but at the same time, it comes with its fair share of risks. A considerable proportion of the browsing is done with the help of android smartphones.Recognising whether malware is on the phone is very crucial to protect yourself from it. Malware may be perplexing, interfering with how you regularly use your phone and making you feel anxious, even if you don't know what's causing the issue. It's also relatively frequent. Therefore, we have put together the possible signs of a malware attack on an android in this post.How Does a ... Read More

How to convert a List to a Map in Kotlin?

Soumak De
Updated on 27-Oct-2021 11:31:57

4K+ Views

In this article, we will see how we can convert a List to a Map using various options provided by the Kotlin Library.Example: Using associate()The most standard way of converting a list into a map is by using the associate() function. This function takes a list of items as an argument and it returns a map containing key-value pairs. In the following example, we will see how it works.Exampledata class mySubjectList(var name: String, var priority: String) fun main() {    val mySubjectList: List = listOf(       mySubjectList("Java", "1"),       mySubjectList("Kotlin", "2"),       mySubjectList("C", ... Read More

How to call a function after a delay in Kotlin?

Soumak De
Updated on 27-Oct-2021 11:21:22

3K+ Views

Kotlin is based on Java, hence we can use Java-based library functions to delay a function call. In this article, we will be using a Java library function to delay the function call using Timer() and schedule().Exampleimport java.util.Timer import kotlin.concurrent.schedule fun main(args: Array) {    // Execution starting point    println("Hello world!!")    // Delay of 5 sec    Timer().schedule(5000){       //calling a function       newMethod()    } } fun newMethod(){ println("Delayed method call!") }OutputOnce executed, the above piece of code will yield the following output −Hello world!! Delayed method call!

What's the Kotlin equivalent of Java's String[]?

Soumak De
Updated on 27-Oct-2021 11:14:17

238 Views

String is a collection which is implemented using String class. As per the Kotlin documentation, a string can be defined as follows −Class String : Comparable, CharSequenceIn Kotlin, a string is a collection of characters. Strings are immutable in nature which means they are read-only. The length and elements of a string can be modified once declared.In Java, we have an option to create an empty String array by defining it like String[]. In this article, we will see how we can achieve the same using Kotlin library function.Example: Using arrayOf()Kotlin library provides a function to create an array of ... Read More

How can I get a random number in Kotlin?

Soumak De
Updated on 27-Oct-2021 11:10:06

12K+ Views

Kotlin provides multiple ways to generate a random number. In this article, we will see different ways to generate a random number and access it throughout the program.Example – Using Random classRandom() is an abstract class which generates random numbers with the given conditions. It can be accessed after importing Kotlin.random.Random.As per the Kotlin documentation, the companion object Random.Default is the default instance of Random class. In the following example, we will generate a list of random values with int (1-30) .Exampleimport kotlin.random.Random fun main() {    val myRandomValues = List(5) { Random.nextInt(0, 30) }    // Prints ... Read More

How to get the current index of an array while using forEach loop in Kotlin?

Soumak De
Updated on 27-Oct-2021 11:05:59

4K+ Views

Sometimes it becomes necessary to access the index of an array. In this article, we will see how we can access the index of an array in Kotlin while using forEach loop.Example: Using forEachIndexed()nstead of using forEach() loop, you can use the forEachIndexed() loop in Kotlin. forEachIndexed is an inline function which takes an array as an input and its index and values are separately accessible.In the following example, we will traverse through the "Subject" array and we will print the index along with the value.Examplefun main() { var subject = listOf("Java", "Kotlin", "JS", "C") ... Read More

How does the reified keyword work in Kotlin?

Soumak De
Updated on 27-Oct-2021 11:02:33

3K+ Views

"reified" is a special type of keyword that helps Kotlin developers to access the information related to a class at runtime. "reified" can only be used with inline functions. When "reified" keyword is used, the compiler copies the function’s bytecode to every section of the code where the function has been called. In this way, the generic type T will be assigned to the type of the value it gets as an argument.ExampleIn this example, we will see how "reified" is helpful to re-use our code and use the same function to perform similar kind of operation regardless of its ... Read More

What is the Kotlin double-bang (!!) operator?

Soumak De
Updated on 27-Oct-2021 10:59:30

3K+ Views

In Kotlin, "!!" is an operator that is known as the double-bang operator. This operator is also known as "not-null assertion operator". This operator is used to convert any value to a non-NULL type value and it throws an exception if the corresponding value is NULL. In the following example, we will see how to use this double-bang operator.Example 1In this example, we will consider a variable "name" and as a programmer, we want to throw a NULL pointer exception whenever the value of "name" is NULL. Now, execute the following codefun main(args: Array) { var name: ... Read More

Difference between List and Array types in Kotlin

Soumak De
Updated on 27-Oct-2021 10:56:27

4K+ Views

List and array are two popular collections supported by Kotlin. By definition, both these collections allocate sequential memory location. In this article, we will take an example to demonstrate the difference between these two types of collections.AttributeArrayListImplementationArray is implemented using Array classList or MutableList interfaces are used to implement a List in KotlinMutableArray is mutable, i.e., the values can be changed.List is immutable in nature. In order to create a mutable list, MutableList interface needs to be used.SizeArray is of fixed size. It cannot increase and decrease in size.MutableList do have 'add' and 'remove' functions in order to increase or ... Read More

Extend data class in Kotlin

Soumak De
Updated on 27-Oct-2021 10:52:51

3K+ Views

Data class is a class that holds the data for an application. It is just like a POJO class that we use in Java in order to hold the data.In Java, for data class, we need to create getter and setter methods in order to access the properties of that class. In Kotlin, when a class is declared as a data class, the compiler automatically creates some supporting methods required to access the member variable of the class. The compiler will create getters and setters for the constructor parameters, hashCode(), equals(), toString(), copy().For a class to be considered as a ... Read More

Advertisements