Skip to content

Instantly share code, notes, and snippets.

@astagi
Created February 6, 2013 15:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save astagi/4723136 to your computer and use it in GitHub Desktop.
Save astagi/4723136 to your computer and use it in GitHub Desktop.
Extend this class to transofrm your activity in a splash screen activity for Android!
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
public class SplashScreenActivity extends Activity {
private Handler splashTimeout = new Handler();
private Class<?> cls;
private long time;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
public void setActivityTime(Class<?> cls, long time) {
this.cls = cls;
this.time = time;
}
@Override
protected void onResume() {
super.onResume();
splashTimeout.postDelayed(new Runnable() {
@Override
public void run() {
Intent intent = new Intent(SplashScreenActivity.this, cls);
startActivity(intent);
SplashScreenActivity.this.finish();
}
}, time);
}
@Override
public void onDestroy() {
super.onDestroy();
if(splashTimeout != null)
splashTimeout.removeMessages(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment