2016-06-18 3 views
-2

私は、スプラッシュスクリーンを6秒間表示するAndroidアプリケーションを持っていますが、スプラッシュスクリーンはアプリケーションを開くときに表示されず、代わりに以前のスタートページだったスクリーンが表示されます。ここで スプラッシュスクリーンが表示されない

splashscreen.javaファイルです。ここで

import android.content.Intent; 
import android.support.v7.app.AppCompatActivity; 
import android.os.Bundle; 
import android.view.Menu; 
import android.view.MenuItem; 
import android.os.Handler; 
public class splashscreen extends AppCompatActivity { 
    private static int SPLASH_TIME_OUT = 6000; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_splashscreen); 

     new Handler().postDelayed(new Runnable() { 

      // Using handler with postDelayed called runnable run method 

      @Override 
      public void run() { 
       Intent i = new Intent(splashscreen.this, LoginActivity.class); 
       startActivity(i); 

       // close this activity 
       //finish(); 
      } 
     }, 6*1000); 
    } 

    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.menu_splashscreen, menu); 
     return true; 
    } 

    @Override 
    public boolean onOptionsItemSelected(MenuItem item) { 
     // Handle action bar item clicks here. The action bar will 
     // automatically handle clicks on the Home/Up button, so long 
     // as you specify a parent activity in AndroidManifest.xml. 
     int id = item.getItemId(); 

     //noinspection SimplifiableIfStatement 
     if (id == R.id.action_settings) { 
      return true; 
     } 

     return super.onOptionsItemSelected(item); 
    } 
} 

...

ここでは私の manifestファイル -

​​

あるsplashscreen.xmlファイル -

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" 
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="16dp" 
    android:paddingTop="56dp" 
    android:paddingBottom="56dp" 
    android:background="@drawable/back1" 
    tools:context="com.example.lenovo.doccorduser.splashscreen"> 

    <ImageView 
     android:id="@+id/imgLogo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:src="@drawable/foetus" 
     android:layout_alignTop="@+id/textView4" 
     android:layout_centerHorizontal="true" /> 

    <ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:id="@+id/imageView" 
     android:src="@mipmap/doccord" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" /> 

    <TextView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textAppearance="?android:attr/textAppearanceMedium" 
     android:text="DocCord" 
     android:textStyle="bold" 
     android:id="@+id/textView4" 
     android:layout_below="@+id/imageView" 
     android:layout_centerHorizontal="true" 
     android:focusable="false" 
     android:textColor="@android:color/holo_orange_light" /> 

</RelativeLayout> 

が助けてくださいです

+0

あなたはインスタンスを保持せず、ondestroyイベントをオーバーライドしていないことを確認してください。あなたのondestroyコードを表示します。 –

+0

コードが正常であるようです。プロジェクトのクリーニングと再構築を試してください。 –

+0

'Logcat'に' Errors'がありますか?投稿してください。 –

答えて

0

まずクリーンあなたのプロジェクト、

Build -> Clean Project 

して、再度実行してください。それが動作します。

0

こんにちはこのコード試してみてください。

SplashScreen.java

public class splashscreen extends AppCompatActivity { 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.splashscreen); 
    Thread timerThread = new Thread(){ 
     public void run(){ 
      try{ 
       sleep(6000); 
      }catch(InterruptedException e){ 
       e.printStackTrace(); 
      }finally{ 
       Intent intent = new Intent(splashscreen.this,MainActivity.class); 
       startActivity(intent); 
      } 
     } 
    }; 
    timerThread.start(); 
} 

@Override 
protected void onPause() { 
    // TODO Auto-generated method stub 
    super.onPause(); 
    finish(); 
} 

}

SplashScreen.xml

を、

<ImageView 
    android:src="@drawable/mobilewallpapers" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

AndroidManifest

<application 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 
    <activity android:name=".MainActivity"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

     </intent-filter> 
    </activity> 
    <activity android:name=".splashscreen"> 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN"> 

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

      </category> 
     </intent-filter> 
    </activity> 
</application> 

は、それが動作を期待;)

関連する問題