2012-06-10 3 views
0

Я использую код для заставки для приложения для Android, для которого код был отправлен при переполнении стека. Я не могу получить выход. Вот код.Заставка в андроиде не работает

package com.splash; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
public class SplashScreen extends Activity { 

     private static final int SPLASH_DISPLAY_TIME = 3000; 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.splash); 

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

       public void run() { 

        Intent mainIntent = new Intent(Splashscreen.this, 
          MainActivity.class); 
        Splashscreen.this.startActivity(mainIntent); 

        Splashscreen.this.finish(); 
        overridePendingTransition(R.anim.mainfadein, 
          R.anim.splashfadeout); 
       } 
      }, SPLASH_DISPLAY_TIME); 
     } 
    } 
} 

Это файл splash.xml;

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="wrap_content" 
android:layout_height="wrap_content"> 
<ImageView 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:src="@drawable/splash" /> 
</LinearLayout> 

, пожалуйста, сообщите мне, как его решить. У меня также есть файлы fadein и fadeout xml для изображения заставки.

+0

"public class SplashScreen extends Activity {" double is typo error? –

ответ

0

public class SplashScreen extends Activity { дважды в коде ..

сделать сингл.

package com.splash; 

import android.app.Activity; 
import android.content.Intent; 
import android.os.Bundle; 
import android.os.Handler; 
public class SplashScreen extends Activity { 

     private static final int SPLASH_DISPLAY_TIME = 3000; 

     public void onCreate(Bundle savedInstanceState) { 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.splash); 

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

       public void run() { 

        Intent mainIntent = new Intent(Splashscreen.this, 
          MainActivity.class); 
        Splashscreen.this.startActivity(mainIntent); 

        Splashscreen.this.finish(); 
        overridePendingTransition(R.anim.mainfadein, 
          R.anim.splashfadeout); 
       } 
      }, SPLASH_DISPLAY_TIME); 
     } 
    } 
+0

Эй, я проверил его и получил. Спасибо. Но после того, как изображение отображается, приложение перестает получать сообщение об ошибке, так как всплеск приложения (process.com.splash) неожиданно остановился. Повторите попытку. Существует намерение, которое вызывает класс MainActivity: - Intent mainIntent = новое намерение (Splashscreen.this, MainActivity.class); Splashscreen.this.startActivity (mainIntent); Но не работает. Можете ли вы помочь – user1447105

0

Убедитесь, что в AndroidManifest.xml добавлена ​​функция MainActivity. Кроме того, публикация трассировки стека исключений из logcat может помочь.

0

Скорее всего, у вас нет класса «MainActivity». Проверьте правильность его имени. И убедитесь, что он в правильном пакете и добавлен в манифест.

Смежные вопросы