Skip to content

Instantly share code, notes, and snippets.

@guptasanchit90
Created March 31, 2016 09:46
Show Gist options
  • Save guptasanchit90/ae0e9148e3ec857ee964fe5bca02bc88 to your computer and use it in GitHub Desktop.
Save guptasanchit90/ae0e9148e3ec857ee964fe5bca02bc88 to your computer and use it in GitHub Desktop.
A SplashScreen using RxAndroid
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