Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Thread delay = new Thread() {
- @Override
- public void run() {
- try {
- Thread.sleep(3000);
- } catch (InterruptedException e) {
- }
- runOnUiThread(new Runnable() {
- @Override
- public void run() {
- startNextActivity();
- }
- });
- }
- };
- protected int _splashTime = 15000;
- private Handler handler;
- private Runnable runnable;
- private Context context;
- @Override
- public void onCreate(Bundle savedInstance)
- {
- super.onCreate(savedInstance);
- setContentView(R.layout.splash);
- final SplashScreen sPlashScreen = this;
- handler = new Handler();
- runnable = new Runnable() {
- @Override
- public void run() {
- try {
- handler.removeCallbacks(runnable);
- handler.postDelayed(runnable, _splashTime);
- }
- finally {
- finish();
- //start a new activity
- //mtdCheckLicense();
- Intent main = new Intent();
- main.setClass(sPlashScreen, YourMainActivity.class);
- startActivity(main);
- handler.removeCallbacks(runnable);
- }
- }
- };
- handler.postDelayed(runnable, 2000);
- }
- public class SplashActivity extends Activity {
- Handler handler;
- private long timeDelay = 2000; //2 seconds
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.SplashLayout);
- final Intent i = new Intent(this, Landing.class);
- handler = new Handler();
- handler.postDelayed(new Runnable() {
- public void run() {
- startActivity(i);
- finish();
- }
- }, timeDelay);
- }
- }
- public class SplashActivity extends Activity
- {
- private final static int MSG_CONTINUE = 1234;
- private final static long DELAY = 2000;
- @Override
- protected void onCreate(Bundle args)
- {
- super.onCreate(args);
- setContentView(R.layout.activity_splash);
- mHandler.sendEmptyMessageDelayed(MSG_CONTINUE, DELAY);
- }
- @Override
- protected void onDestroy()
- {
- mHandler.removeEmptyMessages(MSG_CONTINUE);
- super.onDestroy();
- }
- private void _continue()
- {
- startActivity(new Intent(this, SomeOtherActivity.class));
- finish();
- }
- private final Handler mHandler = new Handler()
- {
- public void handleMessage(android.os.Message msg)
- {
- switch(msg.what){
- case MSG_CONTINUE:
- _continue();
- break;
- }
- }
- };
- }
- public class SplashActivity extends Activity {
- protected boolean active = true;
- protected int splashTime = 1000;
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.splash_screen);
- Thread splashTread = new Thread() {
- @Override
- public void run() {
- try {
- int waited = 0;
- while(active && (waited < splashTime)) {
- sleep(100);
- if(active) {
- waited += 100;
- }
- }
- } catch(InterruptedException e) {
- // do nothing
- } finally {
- finish();
- // Start your Activity here
- }
- }
- };
- splashTread.start();
- }
- //...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement