2016-04-28 14 views
-6

私はアンドロイド開発の初心者です。「私のアンドロイドアプリのスプラッシュ画面が遅すぎます」という問題に直面しています。ここで私のスプラッシュ画面の読み込みが遅すぎる

は私のspash.javaのソースコードは次のとおりです。

import android.annotation.SuppressLint; 
import android.annotation.TargetApi; 
import android.app.ActionBar; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Build; 
import android.os.Bundle; 

@SuppressLint("NewApi") 
public class Splash extends Activity { 

     @TargetApi(Build.VERSION_CODES.HONEYCOMB) 
     @SuppressLint("NewApi") 
     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.activity_splash); 

      ActionBar actionBar = getActionBar(); 
      actionBar.hide(); 

      Thread t =new Thread(){ 
       public void run(){ 
        try{ 
         sleep(10000); 
        }catch(InterruptedException e){ 
         e.printStackTrace(); 
        }finally{ 
         Intent i =new Intent(Splash.this,MainActivity.class); 
         startActivity(i); 
        } 
       } 
      }; 
      t.start(); 
     } 
     @Override 
     public void onPause(){ 
      super.onPause(); 
      finish(); 
     } 

    } 
+1

スリープ時間を変更すると、2000秒を置く@Rohith –

+0

'sleep(10000);'これは、あなたのスプラッシュ画面が次のアクティビティに行くのに10秒かかることを意味します。 1000または2000のようなものを、より速いlodingに設定します。 –

+0

@ JhamanDas私はsleep(10000)を置き換える必要があります。 (2000年);右 ? – Rohith

答えて

3

変更sleep time2000代わりの10000を入れて、それが2秒

+0

答えのためのThanx – Rohith

+0

@Rohithは答えとして受け入れるのでスレッドは閉じます –

+0

5分で受け入れることができます – Rohith

0

のためになり、それが動作するコードの下に試してみてください。あなたはより多くの負荷がかかるThreadスリープ時間を変更する必要があなたのコードで

public class ViewSplashScreen extends AppCompatActivity implements View.OnClickListener,Runnable { 
    RelativeLayout rltvGetstarted; 
    Activity thisActivity; 
    private Handler mHandler; 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, 
       WindowManager.LayoutParams.FLAG_FULLSCREEN); 
     /*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { 
      Window window = getWindow(); 
      window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); 
      window.setStatusBarColor(Color.TRANSPARENT); 
     }*/ 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.act_splashscreen); 
     mHandler = new Handler(); 
     mHandler.postDelayed(this, 1000); 
     /*init*/ 
     init(); 
    } 

    private void init() { 
     thisActivity = this; 
     rltvGetstarted = (RelativeLayout) findViewById(R.id.rltv_getstarted); 
     rltvGetstarted.setOnClickListener(this); 
    } 

    @Override 
    public void onClick(View v) { 
     if (v==rltvGetstarted){ 
      CM.startActivity(thisActivity,ViewMobileNo.class); 
     } 
    } 

    @Override 
    public void run() { 
     //if user already login 
     //CM.startActivity(thisActivity,ViewMobileNo.class); 
     CM.startActivity(thisActivity,ViewBase.class); 
     finish(); 
    } 

} 
+0

答えのためのThanx – Rohith

+0

上記のコメントを参照してください。 –

0

...

が更新とコードの下に見る、ここsleep(10000);は、これらのコードを試してみてくださいsleep(2000);

import android.annotation.SuppressLint; 
import android.annotation.TargetApi; 
import android.app.ActionBar; 
import android.app.Activity; 
import android.content.Intent; 
import android.os.Build; 
import android.os.Bundle; 

@SuppressLint("NewApi") 
public class Splash extends Activity { 

    @TargetApi(Build.VERSION_CODES.HONEYCOMB) 
    @SuppressLint("NewApi") 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_splash); 

     ActionBar actionBar = getActionBar(); 
     actionBar.hide(); 

     Thread t =new Thread(){ 
      public void run(){ 
       try{ 
        sleep(2000); 
       }catch(InterruptedException e){ 
        e.printStackTrace(); 
       }finally{ 
        Intent i =new Intent(Splash.this,MainActivity.class); 
        startActivity(i); 
       } 
      } 
     }; 
     t.start(); 
    } 
    @Override 
    public void onPause(){ 
     super.onPause(); 
     finish(); 
    } 

} 
+0

答えはThanx – Rohith

+0

上記のコメントを参考にしてください。 –

+0

しかし、私はコードで説明して答えを与えたいと思います。@ jaydroider –

1

を変更するには。このコードは動作します。

SplashScreen.java

public class SplashScreen extends Activity { 

    // Splash screen timer 
    private static int SPLASH_TIME_OUT = 3000; 
    ImageView logo; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.splash_screen_one); 

     logo = (ImageView) findViewById(R.id.imgLogo); 

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

      /* 
      * Showing splash screen with a timer. This will be useful when you 
      * want to show case your app logo/company 
      */ 

      @Override 
      public void run() { 
       // This method will be executed once the timer is over 
       // Start your app main activity 
       Intent i = new Intent(SplashScreen.this, MainActivity.class); 
       startActivity(i); 

       // close this activity 
       finish(); 
      } 
     }, SPLASH_TIME_OUT); 
    } 

} 

XMLファイルは以下の通りです: - これはまたとしてスプラッシュ画面が表示されます助けるかもしれ

splash_screen_one.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"> 

    <ImageView 
     android:id="@+id/imgLogo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:background="@drawable/logo_xelenlentro"/> 

    <ProgressBar 
     android:id="@+id/ProgressBar" 
     style="@android:style/Widget.Holo.ProgressBar.Large" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerHorizontal="true" 
     android:layout_below="@+id/imgLogo" 
     android:layout_centerVertical="true" 
     android:visibility="visible"></ProgressBar> 


</RelativeLayout> 
+0

上記のコメントを見てください。 –

+0

答えのためのThanx – Rohith

+0

あなたの問題を解決するなら答えをupvoteしてください –

0

・ホープ5秒間の睡眠時間で

Thread background = new Thread() { 
     public void run() { 

     try { 
     sleep(5*1000); 

     Intent i=new Intent(SplashScreen.this, 
       MainActivity.class); 
     startActivity(i); 
     finish(); 

      } catch (Exception e) { 

      } 
     } 
    }; 

    background.start(); 

詳細 - >Splash Screen

関連する問題