π§
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
public class SingletonClass { | |
private static SingletonClass sSoleInstance; | |
//private constructor. | |
private SingletonClass(){ | |
//Prevent form the reflection api. | |
if (sSoleInstance != null){ | |
throw new RuntimeException("Use getInstance() method to get the single instance of this class."); |
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
public class SingletonClass { | |
private static volatile SingletonClass sSoleInstance; | |
//private constructor. | |
private SingletonClass(){ | |
//Prevent form the reflection api. | |
if (sSoleInstance != null){ | |
throw new RuntimeException("Use getInstance() method to get the single instance of this class."); |
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
public class SingletonClass { | |
private static volatile SingletonClass sSoleInstance = new SingletonClass(); | |
//private constructor. | |
private SingletonClass(){} | |
public static SingletonClass getInstance() { | |
return sSoleInstance; | |
} |
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
public class SingletonTester { | |
public static void main(String[] args) { | |
try { | |
SingletonClass instance1 = SingletonClass.getInstance(); | |
ObjectOutput out = null; | |
out = new ObjectOutputStream(new FileOutputStream("filename.ser")); | |
out.writeObject(instance1); | |
out.close(); |
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
public class SingletonClass implements Serializable { | |
private static volatile SingletonClass sSoleInstance; | |
//private constructor. | |
private SingletonClass(){ | |
//Prevent form the reflection api. | |
if (sSoleInstance != null){ | |
throw new RuntimeException("Use getInstance() method to get the single instance of this class."); |
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<String> database = Observable //Observable. This will emit the data | |
.just(new String[]{"1", "2", "3", "4"}); //Operator | |
Observer<String> observer = new Observer<String>() { | |
@Override | |
public void onCompleted() { | |
//... | |
} | |
@Override |
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
dependencies { | |
compile 'io.reactivex:rxandroid:1.2.1' | |
// Because RxAndroid releases are few and far between, it is recommended you also | |
// explicitly depend on RxJava's latest version for bug fixes and new features. | |
compile 'io.reactivex:rxjava:1.1.6' | |
} |
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.just(1, 2, 3, 4, 5) |
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 | |
.just(1, 2, 3, 4, 5) | |
.filter(new Func1<Integer, Boolean>() { | |
@Override | |
public Boolean call(Integer integer) { | |
//check if the number is odd? If the number is odd return true, to emmit that object. | |
return integer % 2 != 0; | |
} | |
}); |
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<Integer> observable = Observable | |
.just(1, 2, 3, 4, 5) | |
.filter(new Func1<Integer, Boolean>() { | |
@Override | |
public Boolean call(Integer integer) { | |
//check if the number is odd? If the number is odd return true, to emmit that object. | |
return integer % 2 != 0; | |
} | |
}); |