-
-
Save pyadav/4d7344ddcff4cf76bfe85a0b5368a754 to your computer and use it in GitHub Desktop.
A SplashScreen using RxAndroid
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
| 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