SHARE
TWEET

Untitled

a guest Feb 19th, 2019 57 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Thread delay = new Thread() {
  2.     @Override
  3.     public void run() {
  4.         try {
  5.             Thread.sleep(3000);
  6.         } catch (InterruptedException e) {
  7.         }
  8.  
  9.         runOnUiThread(new Runnable() {
  10.             @Override
  11.             public void run() {
  12.                 startNextActivity();
  13.             }
  14.         });
  15.     }
  16. };
  17.    
  18. protected int _splashTime = 15000;
  19.  
  20. private Handler handler;
  21. private Runnable runnable;
  22.  
  23. private Context context;
  24.  
  25.  
  26. @Override
  27. public void onCreate(Bundle savedInstance)
  28. {
  29.     super.onCreate(savedInstance);
  30.     setContentView(R.layout.splash);  
  31.  
  32.     final SplashScreen sPlashScreen = this;
  33.  
  34.     handler = new Handler();
  35.  
  36.      runnable = new Runnable() {
  37.          @Override
  38.             public void run() {
  39.              try {
  40.                 handler.removeCallbacks(runnable);
  41.                 handler.postDelayed(runnable, _splashTime);
  42.               }  
  43.             finally {
  44.                 finish();
  45.                 //start a new activity
  46.  
  47.                 //mtdCheckLicense();
  48.                 Intent main = new Intent();
  49.                 main.setClass(sPlashScreen, YourMainActivity.class);
  50.                 startActivity(main);
  51.                 handler.removeCallbacks(runnable);
  52.  
  53.             }
  54.         }
  55.     };
  56.     handler.postDelayed(runnable, 2000);
  57. }
  58.    
  59. public class SplashActivity extends Activity {
  60.     Handler handler;
  61.     private long timeDelay = 2000; //2 seconds
  62.     @Override
  63.     public void onCreate(Bundle savedInstanceState) {
  64.         super.onCreate(savedInstanceState);
  65.         setContentView(R.layout.SplashLayout);
  66.         final Intent i = new Intent(this, Landing.class);
  67.         handler = new Handler();
  68.         handler.postDelayed(new Runnable() {
  69.              public void run() {
  70.                  startActivity(i);
  71.                  finish();
  72.              }
  73.         }, timeDelay);
  74.     }      
  75. }
  76.    
  77. public class SplashActivity extends Activity
  78. {
  79.     private final static int MSG_CONTINUE = 1234;
  80.     private final static long DELAY = 2000;
  81.  
  82.     @Override
  83.     protected void onCreate(Bundle args)
  84.     {
  85.         super.onCreate(args);
  86.         setContentView(R.layout.activity_splash);
  87.  
  88.         mHandler.sendEmptyMessageDelayed(MSG_CONTINUE, DELAY);
  89.     }
  90.  
  91.     @Override
  92.     protected void onDestroy()
  93.     {
  94.         mHandler.removeEmptyMessages(MSG_CONTINUE);
  95.         super.onDestroy();
  96.     }
  97.  
  98.     private void _continue()
  99.     {
  100.         startActivity(new Intent(this, SomeOtherActivity.class));
  101.         finish();
  102.     }
  103.  
  104.     private final Handler mHandler = new Handler()
  105.     {
  106.         public void handleMessage(android.os.Message msg)
  107.         {
  108.             switch(msg.what){
  109.                 case MSG_CONTINUE:
  110.                     _continue();
  111.                     break;
  112.             }
  113.         }
  114.     };
  115. }
  116.    
  117. public class SplashActivity extends Activity {
  118.     protected boolean active = true;
  119.     protected int splashTime = 1000;
  120.  
  121.     @Override
  122.     public void onCreate(Bundle savedInstanceState) {
  123.         super.onCreate(savedInstanceState);
  124.         setContentView(R.layout.splash_screen);
  125.         Thread splashTread = new Thread() {
  126.             @Override
  127.             public void run() {
  128.                 try {
  129.                     int waited = 0;
  130.                     while(active && (waited < splashTime)) {
  131.                         sleep(100);
  132.                         if(active) {
  133.                             waited += 100;
  134.                         }
  135.                     }
  136.                 } catch(InterruptedException e) {
  137.                     // do nothing
  138.                 } finally {
  139.                     finish();
  140.                     // Start your Activity here
  141.                }
  142.            }
  143.        };
  144.        splashTread.start();    
  145.    }
  146.  //...
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top