Core Android Framework, Systems

By pjain      Published Dec. 16, 2019, 6:04 a.m. in blog Programming   

Activity, Core Framework 101


Activity Lifecycle, Actions in Activity

onCreate() {
    override fun onBackPressed() {

Activity Core with Data Binding "Synthetic" in Kotlin, lateinit, lazy

  • PKJQ ?is the synthetic.main.* requrired?

  • Code in MobAndrw/kotlin/

    import import android.os.Bundle import import

    class MainActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_main) //<-- data bound by kotlin synthetic -> main/ res/layout/ activity_main.xml btn_show_popup.setOnClickListener { // put onclick action here }

    // activity_main.xml has a button
    constraintLayout &gt; &lt;Button id:btn_show_popup text="show popup"



Simple Intents, Data Passing and ActivityResult

Simple Intents

&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout  xmlns:android="" android:padding="25dp"
    android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" &gt;
    &lt;Button android:id="@+id/btn_explicit"    android:text="Explicit Intent"
        android:layout_width="match_parent"   android:layout_height="wrap_content" /&gt;
    &lt;Button android:id="@+id/btn_implicit"    android:text="Implicit Intent"
        android:layout_width="match_parent"   android:layout_height="wrap_content" /&gt;

import android.content.Intent
class MainActivity : AppCompatActivity() {
  onCreate ..
    val context = this
    btn_explicit.setOnClickListener {  // weird example - relaunch THIS activity after closing this one!
        val intent = Intent(context,
    btn_implicit.setOnClickListener { // Let user pick which to share with eg email .. 
        var intent = Intent(Intent.ACTION_SEND)
        intent.type ="text/plain"

Data Passing

r Data Pass


//ActivityResultEx - ux &lt;btn_read open file&gt; _______ tv_read_data read data TV _______
  • Manifest needs

    const val FILE_PICKER_ID = 12 lateinit var context : Context onCreate {.. context = this btn_read.setOnClickListener({ var intent = Intent(Intent.ACTION_GET_CONTENT) intent.type = "text/*" //set mime type of file for picker .. user will choose .. startActivityForResult(intent,FILE_PICKER_ID) }) } override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { super.onActivityResult(requestCode, resultCode, data) if(requestCode == FILE_PICKER_ID && resultCode == Activity.RESULT_OK){ val dest = File(PathUtils.getPath(context,data!!.data)) val readData = FileInputStream(dest).bufferedReader().use { it.readText() } tv_read_data.text = readData } }

Packaged Intent - EM SMS

Form ET to Send HTML Email

  • uses synthetic binding to get form edit text, submit sends it ..
    val i = Intent(Intent.ACTION_SEND)
    i.type = "text/html"
    i.putExtra(iIntent.EXTRA_EMAIL,arrayOf(""))  // or arrayOf&lt;String&gt;(...) 
    i.putExtra(iIntent.EXTRA_CC,   arrayOf(""))
    i.putExtra(iIntent.EXTRA_BCC,  arrayOf(""))
    i.putExtra(iIntent.EXTRA_SUBJECT,"RE: asdf subject")
    i.putExtra(iIntent.EXTRA_TEXT, arrayOf("html email body"))

AsyncTask, Job

// ~wmkt/DemoAsyncTask


BroadcastReceivers and Notifications



// ~wmkt/IntentServiceExample

Pending Intent, Service Intent


// ~wmkt/NotificationExample

Alarms Manager

Timer, Clock

Make a Timer App: Countdown Timer in Kotlin (Ep 2 of 3)

Alarm Manager, DB


Reminders, Alarms, Timers

// ~wmkt/


There are no comments yet

Add new comment

Similar posts

Serverless Computing

Android Layouts Design 101

Drawing, Canvas in Kotlin

Custom Views