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
| val job = launch { // launch a new coroutine and keep a reference to its Job | |
| delay(1000L) | |
| println("World!") | |
| } | |
| println("Hello") | |
| job.join() // wait until child coroutine completes | |
| println("Done") |
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
| import kotlinx.coroutines.* | |
| fun main() = runBlocking { | |
| repeat(100_000) { // launch a lot of coroutines | |
| launch { | |
| delay(5000L) | |
| print(".") | |
| } | |
| } | |
| } |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <manifest xmlns:android="http://schemas.android.com/apk/res/android" | |
| xmlns:tools="http://schemas.android.com/tools"> | |
| <application | |
| android:allowBackup="true" | |
| android:dataExtractionRules="@xml/data_extraction_rules" | |
| android:fullBackupContent="@xml/backup_rules" | |
| android:icon="@mipmap/ic_launcher" | |
| android:label="@string/app_name" |
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
| import android.app.Service | |
| import android.content.Intent | |
| import android.os.IBinder | |
| class MyAppService: Service() { | |
| private var startMode: Int = 0 // indicates how to behave if the service is killed | |
| private var binder: IBinder? = null // interface for clients that bind | |
| private var allowRebind: Boolean = false // indicates whether onRebind should be used |
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
| import android.app.Service | |
| import android.content.Intent | |
| import android.os.IBinder | |
| class AudioLoopService : Service() { | |
| override fun onBind(intent: Intent?): IBinder? { | |
| TODO("Not yet implemented") | |
| } | |
| } |
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
| import android.os.Bundle | |
| import androidx.appcompat.app.AppCompatActivity | |
| import com.alokomkar.javacollections.R | |
| class HomeActivity: AppCompatActivity() { | |
| override fun onCreate(savedInstanceState: Bundle?) { | |
| super.onCreate(savedInstanceState) | |
| setContentView(R.layout.activity_home) | |
| } |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <FrameLayout | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent"> | |
| <androidx.fragment.app.FragmentContainerView | |
| android:name="com.alokomkar.activity.HomeFragment" | |
| android:id="@+id/homeFragment" | |
| android:layout_width="match_parent" |
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
| import android.app.Service | |
| import android.content.Intent | |
| import android.media.MediaPlayer | |
| import android.os.IBinder | |
| import com.alokomkar.javacollections.R | |
| class AudioLoopService : Service() { | |
| private val mediaPlayer: MediaPlayer by lazy { | |
| MediaPlayer.create(this, R.raw.sample_audio) |
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
| import android.content.Intent | |
| import android.os.Bundle | |
| import android.view.LayoutInflater | |
| import android.view.View | |
| import android.view.ViewGroup | |
| import androidx.appcompat.widget.AppCompatButton | |
| import androidx.fragment.app.Fragment | |
| import com.alokomkar.javacollections.R | |
| import com.alokomkar.service.AudioLoopService |
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
| <?xml version="1.0" encoding="utf-8"?> | |
| <androidx.appcompat.widget.LinearLayoutCompat | |
| xmlns:android="http://schemas.android.com/apk/res/android" | |
| android:orientation="vertical" | |
| android:layout_width="match_parent" | |
| android:layout_height="match_parent" | |
| android:gravity="center"> | |
| <androidx.appcompat.widget.AppCompatButton | |
| android:layout_width="match_parent" |