Create Observable using fromArray method in RxJava

Constructs a sequence from a pre-existing source or generator type.
Signals the elements of the given array and then completes the sequence.

String[] array = new String[10];
for (int i = 0; i < array.length; i++) {
    array[i] = String.valueOf(i);
}

Observable<String> observable = Observable.fromArray(array);

observable.subscribe(s -> {
    System.out.println(s);
});

References
https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#fromarray

Create Observable using fromIterable method in RxJava

Constructs a sequence from a pre-existing source or generator type.
Signals the items from a java.lang.Iterable source (such as Lists, Sets or Collections or custom Iterables) and then completes the sequence.

List<String> list = new ArrayList<>();
list.add("1");
list.add("2");
list.add("3");

Observable<String> observable = Observable.fromIterable(list);

observable.subscribe(s -> {
    System.out.println(s);
});

References
https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#fromiterable

Create Observable using just method in RxJava

Constructs a reactive type by taking a pre-existing object and emitting that specific object to the downstream consumer upon subscription.

Observable<String> observable = Observable.just("1");

observable.subscribe(s -> {
    System.out.println(s);
});
Observable<String> observable = Observable.just("1", "2", "3", "4");

observable.subscribe(s -> {
    System.out.println(s);
});

References
https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#just

Create Observable using create method in RxJava

Construct a safe reactive type instance which when subscribed to by a consumer, runs an user-provided function and provides a type-specific Emitter for this function to generate the signal(s) the designated business logic requires. This method allows bridging the non-reactive, usually listener/callback-style world, with the reactive world.

Observable<String> observable = Observable.create(emitter -> {
    emitter.onNext("1");
    emitter.onNext("2");
    emitter.onComplete();
});

observable.subscribe(s -> {
    System.out.println(s);
});

References
https://www.vogella.com/tutorials/RxJava/article.html#creating-observables
https://www.tutorialspoint.com/rxjava/rxjava_creating_operators.htm
https://github.com/ReactiveX/RxJava/wiki/Creating-Observables#create

Save terminal output to a file

          || visible in terminal ||   visible in file   || existing
  Syntax  ||  StdOut  |  StdErr  ||  StdOut  |  StdErr  ||   file   
==========++==========+==========++==========+==========++===========
    >     ||    no    |   yes    ||   yes    |    no    || overwrite
    >>    ||    no    |   yes    ||   yes    |    no    ||  append
          ||          |          ||          |          ||
   2>     ||   yes    |    no    ||    no    |   yes    || overwrite
   2>>    ||   yes    |    no    ||    no    |   yes    ||  append
          ||          |          ||          |          ||
   &>     ||    no    |    no    ||   yes    |   yes    || overwrite
   &>>    ||    no    |    no    ||   yes    |   yes    ||  append
          ||          |          ||          |          ||
 | tee    ||   yes    |   yes    ||   yes    |    no    || overwrite
 | tee -a ||   yes    |   yes    ||   yes    |    no    ||  append
          ||          |          ||          |          ||
 n.e. (*) ||   yes    |   yes    ||    no    |   yes    || overwrite
 n.e. (*) ||   yes    |   yes    ||    no    |   yes    ||  append
          ||          |          ||          |          ||
|& tee    ||   yes    |   yes    ||   yes    |   yes    || overwrite
|& tee -a ||   yes    |   yes    ||   yes    |   yes    ||  append
  • command > output.txt

    The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.

  • command >> output.txt

    The standard output stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

  • command 2> output.txt

    The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, it gets overwritten.

  • command 2>> output.txt

    The standard error stream will be redirected to the file only, it will not be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

  • command &> output.txt

    Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, it gets overwritten.

  • command &>> output.txt

    Both the standard output and standard error stream will be redirected to the file only, nothing will be visible in the terminal. If the file already exists, the new data will get appended to the end of the file..

  • command | tee output.txt

    The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, it gets overwritten.

  • command | tee -a output.txt

    The standard output stream will be copied to the file, it will still be visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

  • command |& tee output.txt

    Both the standard output and standard error streams will be copied to the file while still being visible in the terminal. If the file already exists, it gets overwritten.

  • command |& tee -a output.txt

    Both the standard output and standard error streams will be copied to the file while still being visible in the terminal. If the file already exists, the new data will get appended to the end of the file.

References
https://askubuntu.com/questions/420981/how-do-i-save-terminal-output-to-a-file

Upgrade to Android Oreo and issue with Firebase Cloud Messaging

create a channel id

<string name="default_notification_channel_id" translatable="false">fcm_default_channel</string>

add a meta-data in manifest file

<application>
...
<meta-data        android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="@string/default_notification_channel_id"/>
</application>

channel assignment

...
// Since android Oreo notification channel is needed.
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    String channelId = context.getString(R.string.default_notification_channel_id);
    NotificationChannel channel = new NotificationChannel(channelId,   title, NotificationManager.IMPORTANCE_DEFAULT);
    channel.setDescription(body);
    mNotificationManager.createNotificationChannel(channel);
    builder.setChannelId(channelId);
}
mNotificationManager.notify(1, notification);
...

References
https://medium.com/globallogic-latinoamerica-mobile/firebase-cloud-messaging-warning-updating-to-android-oreo-1343fe894bd5
https://firebase.google.com/docs/cloud-messaging/android/receive