This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomStaticBroadcastReceiver : BroadcastReceiver() { | |
override fun onReceive(context: Context?, intent: Intent) { | |
if (ConnectivityManager.CONNECTIVITY_ACTION == intent.action) { | |
Toast.makeText(context, "Connectivity changed", Toast.LENGTH_SHORT).show() | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sealed class User { | |
object Name : User(){ | |
// We can override equals function | |
override fun equals(other: Any?): Boolean { return super.equals(other) } | |
// We can override hashCode function | |
override fun hashCode(): Int { return super.hashCode() } | |
// We can override toString function | |
override fun toString(): String { return super.toString() } | |
} | |
data object Age : User() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data object Age { | |
private const val default : Int = 0 | |
fun printDefaultAge(): Int { | |
return default | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MainActivity : AppCompatActivity() { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
println(User.Name) | |
println(User.Age) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kotlinOptions { | |
jvmTarget = '1.8' | |
languageVersion = '1.8' | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'org.jetbrains.kotlin.android' version '1.7.20' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomBackgroundThread : Thread() { | |
private var handler: Handler? = null | |
override fun run() { | |
super.run() | |
Looper.prepare() // Prepare the looper and associate with current thread | |
handler = Handler() | |
Looper.loop() // Start the thread so that it can keep the thread active | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class HandlerOne(handlerTag: String) : HandlerThread(handlerTag) { | |
private lateinit var handler : Handler | |
init { | |
start() | |
handler = Handler(looper) | |
} | |
fun execute( runnable: Runnable) : HandlerOne { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomRunnableOne : Runnable { | |
override fun run() { | |
try { | |
val TAG_ONE = "one" | |
for (i in 0 until 5) { | |
Thread.sleep(500L) | |
println(TAG_NARUTO.plus("--$i--").plus("Current Runnable-->$TAG_ONE")) | |
} | |
}catch (ex:InterruptedException){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class CustomThreadOne : Thread() { | |
override fun run() { | |
try { | |
val TAG_ONE = "one" | |
for (i in 0 until 5) { | |
Thread.sleep(500L) | |
println(TAG_SASUKE.plus("--$i--").plus(name).plus("--").plus(TAG_ONE)) | |
} | |
}catch (ex:InterruptedException){ | |
println(TAG_SASUKE.plus("--").plus("Thread named").plus("--").plus(name).plus("--").plus("is interrupted")) |