Created
July 9, 2016 12:22
-
-
Save nosix/19d1b58a20d65b1dd60216c012afdf9a to your computer and use it in GitHub Desktop.
UpdateReceiver for Android (SDK 22) in Kotlin 1.0.2
This file contains 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() { | |
private val updateReceiver = UpdateReceiver(this) | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
registerReceiver(updateReceiver, IntentFilter(SampleService.ACTION_SAMPLE)) | |
} | |
class UpdateReceiver(val activity: MainActivity) : BroadcastReceiver() { | |
override fun onReceive(context: Context, intent: Intent) { | |
Log.d(TAG, intent.getStringExtra(SampleService.EXTRA_STRING)) | |
} | |
} | |
} |
This file contains 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 SampleService : IntentService(SampleService::class.simpleName) { | |
companion object { | |
val ACTION_SAMPLE = "ACTION_SAMPLE" | |
val EXTRA_STRING = "EXTRA_STRING" | |
} | |
override fun onHandleIntent(intent: Intent) { | |
sendBroadcast(Intent(ACTION_SAMPLE).putExtra(EXTRA_STRING, "sample")) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment