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 RandomNumberGeneratorService:Service() { | |
val binder: IBinder = RandomNumberGeneratorServiceBinder() | |
inner class RandomNumberGeneratorServiceBinder : Binder(){ | |
val service: RandomNumberGeneratorService = this@RandomNumberGeneratorService | |
} | |
override fun onBind(intent: Intent): IBinder { | |
return binder | |
} | |
} |
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
var randomNumberGeneratorService: RandomNumberGeneratorService? = null | |
private lateinit var connection: ServiceConnection | |
var bounded = false | |
val TAG = MainActivity::class.java.simpleName | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
connection = object : ServiceConnection{ | |
override fun onServiceDisconnected(componentName: ComponentName) { | |
Log.d(TAG,"Service disconnected.") |
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() { | |
var randomNumberGeneratorService: RandomNumberGeneratorService? = null | |
private lateinit var connection: ServiceConnection | |
var bounded = false | |
val TAG = MainActivity::class.java.simpleName | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
setContentView(R.layout.activity_main) | |
connection = object : ServiceConnection{ | |
override fun onServiceDisconnected(componentName: ComponentName) { |
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 RandomNumberGeneratorService:Service() { | |
private val binder: IBinder = RandomNumberGeneratorServiceBinder() | |
private lateinit var handlerThread:HandlerThread | |
private lateinit var handler: Handler | |
var randomNumber: Int = -1 | |
private val TAG = RandomNumberGeneratorService::class.java.simpleName | |
private lateinit var mNM: NotificationManager | |
private val NOTIFICATION = R.string.local_service_started | |
private val HANDLER_THREAD_NAME="random_number_generator_thread" | |
private lateinit var notificationBuilder: NotificationCompat.Builder |
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
Observable.fromArray(1,2,3) | |
.doOnNext { | |
if(it==2){ | |
throw (RuntimeException("Exception on 2")) | |
} | |
} | |
.retry(3) | |
.subscribeBy( | |
onNext = { | |
println(it) |
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
Observable.fromArray(1,2,3) | |
.doOnNext { | |
if(it==2){ | |
throw (RuntimeException("Exception on 2")) | |
} | |
} | |
.retry() | |
.subscribeBy( | |
onNext = { | |
println(it) |
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
Observable.fromArray(1,2,3) | |
.doOnNext { | |
if(it==2){ | |
throw (RuntimeException("Exception on 2")) | |
} | |
} | |
.onErrorReturn{ | |
t: Throwable -> | |
if(t.message=="<something you want>"){ | |
1 // Return a value based on error type |
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
Observable.fromArray(1,2,3) | |
.doOnNext { | |
if(it==2){ | |
throw (RuntimeException("Exception on 2")) | |
} | |
} | |
.onErrorReturnItem (-1) | |
.subscribeBy( | |
onNext = { | |
println(it) |
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
Observable.fromArray(1,2,3) | |
.doOnNext { | |
if(it==2){ | |
throw (RuntimeException("Exception on 2")) | |
} | |
} | |
.doOnError { | |
println("Doing on error") | |
} | |
.subscribeBy( |
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
Observable.fromArray(1,2,3) | |
.doOnNext { | |
if(it==2){ | |
throw (RuntimeException("Exception on 2")) | |
} | |
} | |
.onExceptionResumeNext(Observable.just(10)) | |
.subscribeBy( | |
onNext = { | |
println(it) |
NewerOlder