Advertisement
Guest User

MainActivity

a guest
Mar 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Kotlin 1.60 KB | None | 0 0
  1. const val EXTRA_DOWNLOAD_STATUS ="download_Status"
  2.  
  3. class MainActivity : AppCompatActivity() {
  4.  
  5.     private val downloadReceiver = object : BroadcastReceiver(){
  6.         override fun onReceive(p0: Context?, p1: Intent?) {
  7.             Toast.makeText(this@MainActivity, "proses",Toast.LENGTH_SHORT).show()
  8.             var selesai = p1?.getBooleanExtra(EXTRA_FINISH,false)
  9.             var persenSelesai = p1?.getIntExtra(EXTRA_PERSEN,0)
  10.             myProgerss.progress = persenSelesai!!
  11.             if(selesai!!){
  12.                 Toast.makeText(this@MainActivity, "Selesai Download",Toast.LENGTH_SHORT).show()
  13.             }
  14.         }
  15.     }
  16.  
  17.     override fun onCreate(savedInstanceState: Bundle?) {
  18.         super.onCreate(savedInstanceState)
  19.         setContentView(R.layout.activity_main)
  20.         val mDownloadService = Intent (this, MyDownloadService::class.java)
  21.         startMyService.setOnClickListener {
  22.             Toast.makeText(this@MainActivity, "Download Dimulai",Toast.LENGTH_SHORT).show()
  23.             startService(mDownloadService)
  24.         }
  25.         stopMyService.setOnClickListener {
  26.             stopService(mDownloadService)
  27.         }
  28.         val filterReceiver = IntentFilter(EXTRA_DOWNLOAD_STATUS)
  29.         filterReceiver.setPriority(Integer.MAX_VALUE)
  30.         registerReceiver(downloadReceiver,filterReceiver)
  31.     }
  32.     override fun onDestroy() {
  33.         unregisterReceiver(downloadReceiver)
  34.         super.onDestroy()
  35.     }
  36.  
  37. }
  38.  
  39. private operator fun Int.invoke(maX_VALUE: Int) {
  40.     TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement