Created
March 31, 2016 09:46
-
-
Save guptasanchit90/ae0e9148e3ec857ee964fe5bca02bc88 to your computer and use it in GitHub Desktop.
A SplashScreen using RxAndroid
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
import android.app.Activity; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import java.util.concurrent.TimeUnit; | |
import rx.Observable; | |
import rx.Observer; | |
import rx.Subscription; | |
public class SplashScreen extends Activity { | |
private Subscription subscription; | |
Observer observer = new Observer() { | |
@Override | |
public void onCompleted() { | |
} | |
@Override | |
public void onError(Throwable e) { | |
} | |
@Override | |
public void onNext(Object o) { | |
Intent intent = new Intent(SplashScreen.this, MainActivity.class); | |
startActivity(intent); | |
finish(); | |
} | |
}; | |
@Override | |
public void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_splash); | |
} | |
@Override | |
public void onBackPressed() { | |
subscription.unsubscribe(); | |
super.onBackPressed(); | |
} | |
@Override | |
protected void onPause() { | |
subscription.unsubscribe(); | |
super.onPause(); | |
} | |
@Override | |
protected void onResume() { | |
subscription = Observable.timer(3, TimeUnit.SECONDS).subscribe(observer); | |
super.onResume(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment