2016-02-05 154 views
1

我做了一個飛濺佈局,持續一段時間,然後應該加載其他活動,單獨它完美的工作,但是當它連接到其他活動時,它顯示空白屏幕。飛濺屏幕顯示爲空白屏幕

mainifest文件:

<?xml version="1.0" encoding="utf-8"?> 
<manifest xmlns:android="http://schemas.android.com/apk/res/android" 
    package="andy.propaganda" 
    android:installLocation="auto" > 

    <application 
     android:allowBackup="true" 
     android:icon="@drawable/my_launcher" 
     android:label="@string/app_name" 
     android:supportsRtl="true" 
     android:theme="@style/AppTheme.NoActionBar" 
     > 
     <activity 
      android:name=".shit" 
      android:label="@string/app_name" 
      > 
      <intent-filter> 
       <action android:name="com.coderefer.androidsplashscreenexample.MAINACTIVITY" /> 
       <category android:name="android.intent.category.DEFAULT" /> 
      </intent-filter> 
     </activity> 

     <activity 
      android:name=".Splash" 
      android:label="@string/app_name"> 
      <intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 
     </activity> 
     <!-- ATTENTION: This was auto-generated to add Google Play services to your project for 
      App Indexing. See https://g.co/AppIndexing/AndroidStudio for more information. --> 
     <meta-data 
      android:name="com.google.android.gms.version" 
      android:value="@integer/google_play_services_version" /> 
    </application> 

</manifest> 

splash活動:

package andy.propaganda; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.ImageView; 

/** 
* Created by Andrew on 2/4/2016. 
*/ 
public class Splash extends Activity { 

    //welcome animation 
    ImageView loading_img; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     loading_img = (ImageView)findViewById(R.id.loading_view); 
     final Animation animatable = AnimationUtils.loadAnimation(this, R.anim.welcome_screen_anim); 
     loading_img.setAnimation(animatable); 

// 
     for(int i = 0;i< 100000000;i++); 
     Intent intent = new Intent(this, shit.class); 
     intent.putExtra("jhjh", 8); 
     startActivity(intent); 

    } 

} 

main活動:

package andy.propaganda; 

import android.app.Activity; 
import android.os.Bundle; 

/** 
* Created by Andrew on 2/5/2016. 
*/ 
public class shit extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
    } 
} 

splash.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" android:layout_height="match_parent" 
    android:background="@color/MyBlue" 
    > 
    <ImageView 
     android:layout_width="300dp" 
     android:layout_height="300dp" 
     android:src="@drawable/my_launcher" 
     android:paddingTop="60dp" 
     android:id="@+id/imageView" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 

    <ImageView 
     android:layout_width="75dp" 
     android:layout_height="75dp" 
     android:src="@drawable/loading" 
     android:layout_marginBottom="43dp" 
     android:id="@+id/loading_view" 

     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceLarge" 
     android:text="loading your files" 
     android:id="@+id/welcome_message" 
     android:focusable="false" 
     android:textColor="#010101" 
     android:textSize="@dimen/abc_action_bar_progress_bar_size" 
     android:layout_above="@+id/loading_view" 
     android:layout_alignRight="@+id/imageView" 
     android:layout_alignEnd="@+id/imageView" 
     android:layout_marginBottom="50dp" /> 

</RelativeLayout> 
+0

刪除此行<意圖濾波器> <操作機器人:名稱= 「com.coderefer.androidsplashscreenexample.MAINACTIVITY」/> <類別機器人:名稱=「android.intent .category.DEFAULT「/> 從你的** Shit **清單活動 – Amir

+0

我試過了,但沒有任何區別 – andrew

+0

刪除for循環,而不是那個使用Handler你的代碼似乎很好:) – Amir

回答

2

你應該在啓動畫面上使用計時器而不是for(int i = 0;i< 100000000;i++);,這會等待一段時間,假設5秒並且加載另一個活動。

package andy.propaganda; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.view.animation.Animation; 
import android.view.animation.AnimationUtils; 
import android.widget.ImageView; 

/** 
* Created by Andrew on 2/4/2016. 
*/ 
public class Splash extends Activity { 

    //welcome animation 
    ImageView loading_img; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash); 
     loading_img = (ImageView)findViewById(R.id.loading_view); 
     final Animation animatable = AnimationUtils.loadAnimation(this, R.anim.welcome_screen_anim); 
     loading_img.setAnimation(animatable); 



    new Timer().schedule(new TimerTask() {   
    @Override 
    public void run() { 
     // your task 
     Intent intent = new Intent(this, shit.class); 
     intent.putExtra("jhjh", 8); 
     startActivity(intent); 
    } 
    }, 5000); 

    } 

} 
+0

它工作完美,但是如果我需要執行特定的任務並將其作爲參數發送給下一個活動,那麼在我的情況下,我想要搜索第e完整的設備加載陣列中的所有mps文件並將其發送到下一個活動? – andrew

+0

調度(TimerTask任務,長延遲)方法用於在指定延遲後開始調度指定的執行任務。您可以在運行方法中定義您的任務。 –

1

的所有首先不使用for循環等待時間而不是使用的處理程序像這樣的東西:

<intent-filter> 
       <action android:name="android.intent.action.MAIN" /> 
       <category android:name="android.intent.category.LAUNCHER" /> 
      </intent-filter> 

new Handler().postDelayed(new Runnable() { 
       @Override 
       public void run() { 
        startActivity(new Intent(Splash.this, shit.class)); 
        finish(); 
       } 
      }, 500); 

然後從manifest.xml中刪除此行

其餘的代碼似乎沒問題:)

也看看this鏈接哪個很好解釋了關於初始屏幕

+0

謝謝,按預期工作 – andrew

1

RxJava溶液:

Observable.empty().subscribeOn(AndroidSchadelurs.mainThread()).delay(500, TimeUtils.MILISECONDS).subscribe(this::startActivity(this, new Intent));