Android App Development
Android App Development
Glossary:
hints
password input type
to create your own color, Go to colors.xml file under the values directory of the package and create a new value for
ur color of choice in hex.
Similarly u can make ur own files FOLLOWING THE NAMING CONVENTION, import them and use them.
Mainactivity
fun myClickHandler(view: View) {
Log.i("MainActivity", "Button clicked") // Use a consistent log tag
val hintent = Intent(this, HomeActivity::class.java)
hintent.putExtra("MYKEY", "Allahu Akbar")
startActivity(hintent)
}
SecondAcitivity
// Retrieve data from intent
val data = intent.extras?.getString("MYKEY")
With respect to debugging, 1 unit of code is usually a method or function of that code.
How to generate test cases for your code in android studio:
Right click on the class name, Select context actions and from there select; Generate test cases.
Now select the methods for which u want to generate a test case for.
It will create a new file in the test folder of your package, there u need to define the test cases.
Example:
calculator Calculator;
//oncreate
@Override
protected void setUp() throws Exception {
super.setUp();
Calculator = new calculator();
}
//onDestroy
public void tearDown() throws Exception {
super.tearDown();
}
}
The @override enables u to edit the pre existing method or function without making changes in the original file, with
the use of extension. The “setUp” mehod is similar to “onCreate” method in kotline which generates the layout.
The “assertEquals” checks if the expected value and the generated value are same. If they are same then the test
cases is passed.
“tearDown” is similar to the “onDestroy” Activity lifecycle in Kotlin, which destroys the layout after its don’t utilizing
it.
Types of classes in Kotlin:
Enum classes: Used to model types that represent a finite set of distinct values, such as directions, states,
modes and so forth.
Sealed Classes: Sealed classes are similar to protected classes in java. Once declared it cannot be subclassed
by a class outside the same package where the sealing class is declared.
Runblocking(regular function) = Coroutine scope which blocks the current threat for waiting.
coroutineScope(suspending function) = corutine scope which releases the underlying thread for other ususages.
Launch = launches the coroutine
Suspend = allows you to write a coroutine code outside a coroutine scope.
Default time unit is ms
fun main() = runBlocking { // this: CoroutineScope
launch { // launch a new coroutine and continue
delay(1000L) // non-blocking delay for 1 second (default time unit is ms)
println("World!") // print after delay
}
println("Hello") // main coroutine continues while a previous one is delayed
}