Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. import android.content.Intent;
  2. import android.os.AsyncTask;
  3. import android.os.Bundle;
  4. import android.support.v7.app.AppCompatActivity;
  5. import android.util.Log;
  6.  
  7. public class SplashScreen extends AppCompatActivity {
  8. private static int SPLASH_TIME_OUT = 3000;
  9. @Override
  10. protected void onCreate(Bundle savedInstanceState) {
  11.  
  12. super.onCreate(savedInstanceState);
  13. setContentView(R.layout.activity_splash_screen);
  14.  
  15. try {
  16.  
  17. Log.v(" gonna AsyncTask"," execute AsyncTask");
  18. new AsyncTask<String, String, String>() {
  19.  
  20. @Override
  21. protected void onPreExecute() {
  22. Log.v(" PreExecute AsyncTask"," execute AsyncTask");
  23. }
  24.  
  25. @Override
  26. protected String doInBackground(String... arg0) {
  27. Log.v(" in doInBackground"," execute AsyncTask");
  28. try {
  29.  
  30. Log.v(" sleep doInBackground"," execute AsyncTask");
  31. Thread.sleep(SPLASH_TIME_OUT);
  32.  
  33. } catch (Exception e) {
  34. Log.v(" Exception "," execute AsyncTask");
  35. e.printStackTrace();
  36. }
  37. return null;
  38. }
  39.  
  40. @Override
  41. protected void onPostExecute(String unused) {
  42.  
  43. Log.v(" onPostExecute "," execute AsyncTask");
  44. Intent i = new Intent(SplashScreen.this,
  45. MainActivity.class);
  46. Log.v(" starting Activity "," execute AsyncTask");
  47. startActivity(i);
  48.  
  49. }
  50. }.execute();
  51. } catch (Exception e) {
  52. e.printStackTrace();
  53. }
  54.  
  55.  
  56.  
  57.  
  58. }// end of onCreate
  59.  
  60. }// end of class SplashScreen
  61.  
  62. <?xml version="1.0" encoding="utf-8"?>
  63. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  64. xmlns:tools="http://schemas.android.com/tools"
  65. android:id="@+id/activity_splash_screen"
  66. android:layout_width="match_parent"
  67. android:layout_height="match_parent"
  68. android:paddingBottom="@dimen/activity_vertical_margin"
  69. android:paddingLeft="@dimen/activity_horizontal_margin"
  70. android:paddingRight="@dimen/activity_horizontal_margin"
  71. android:paddingTop="@dimen/activity_vertical_margin"
  72. tools:context="com.example.istiaqueahmed.archeology.SplashScreen">
  73.  
  74. <ImageView
  75.  
  76. android:id="@+id/splash_img"
  77. android:layout_width="170dp"
  78. android:layout_height="112dp"
  79. android:adjustViewBounds="true"
  80. android:scaleType="fitCenter"
  81. android:layout_centerInParent="true"
  82. android:layout_centerHorizontal="true"
  83. android:layout_marginTop="130dp"
  84. android:src="@drawable/splash"
  85. />
  86.  
  87. <TextView
  88. android:id="@+id/developed_by"
  89. android:layout_width="match_parent"
  90. android:layout_height="wrap_content"
  91. android:textAlignment="center"
  92. android:text="@string/developed_by"
  93. android:layout_below="@id/splash_img"
  94. android:textStyle="bold"
  95. android:textSize="13sp"
  96. android:layout_alignParentBottom="true"
  97. android:layout_marginBottom="30dp"
  98.  
  99. />
  100.  
  101.  
  102. </RelativeLayout>
  103.  
  104. <application
  105. android:allowBackup="true"
  106. android:icon="@mipmap/ic_launcher"
  107. android:label="@string/app_name"
  108. android:supportsRtl="true"
  109. android:theme="@style/AppTheme">
  110. >
  111. <activity
  112. android:name=".SplashScreen"
  113. android:noHistory="true"
  114. android:screenOrientation="portrait"
  115.  
  116. >
  117. <intent-filter>
  118. <action android:name="android.intent.action.MAIN" />
  119.  
  120. <category android:name="android.intent.category.LAUNCHER" />
  121. </intent-filter>
  122. </activity>
  123.  
  124. ........
  125. </application>
  126.  
  127. <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
  128. <!-- Customize your theme here. -->
  129. <item name="colorPrimary">@color/colorPrimary</item>
  130. <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
  131. <item name="colorAccent">@color/colorAccent</item>
  132. </style>
  133.  
  134. Thread.sleep(SPLASH_TIME_OUT); // This will sleep your main thread.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement