启动画面活动无法正常工作

时间:2014-07-24 14:45:11

标签: java android splash

您已使用此链接创建了启动画面作为单独的项目:http://www.androidhive.info/2013/07/how-to-implement-android-splash-screen-2/。它确实在我的模拟器上运行。但是,当我在我的应用程序中实现它时。它没用。我不喜欢'知道我的代码有什么问题。我的main.java,splash screen.java和splash.xml如下。请注意,我确实在清单文件中定义了我的活动。任何帮助将不胜感激......

MainActivity.Java

import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;




    public class MainActivity extends Activity implements OnClickListener {
        private MediaPlayer mp;

       @Override
       public void onCreate(Bundle savedInstanceState) { 
           super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_main);
          setVolumeControlStream(AudioManager.STREAM_MUSIC);
          findViewById(R.id.button_1).setOnClickListener(this);
          findViewById(R.id.button_2).setOnClickListener(this);
          findViewById(R.id.button_3).setOnClickListener(this);
       }
       public void onClick(View v) {   
           int resId=1;

       // Release any resources from previous MediaPlayer
          if (mp != null) {   
              mp.release(); 
          } 

          switch (v.getId()) {
          case R.id.button_1: resId = R.raw.button_1; break;
          case R.id.button_2: resId = R.raw.button_2; break;
          case R.id.button_3:
             startActivity(new Intent(MainActivity.this,SecondActivity.class));
             return;

          }

       // Create a new MediaPlayer to play this sound
          mp = MediaPlayer.create(this, resId); 
          mp.start();
       }
    }

SplashScreen.java

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

public class SplashScreen extends Activity {

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

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

        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);
    }

}

activity_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="@drawable/gradient_background" >

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:adjustViewBounds="true"
        android:scaleType="fitXY"
        android:src="@drawable/images235" />

</RelativeLayout>

Android Manifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.Smit.yourbollywoodyourplaylist"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="11" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >       
        <activity
            android:name="info.androidhive.androidsplashscreentimer.SplashScreen"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

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

         <activity
            android:name=".SecondActivity" 
            android:label="@string/app_name"/>
    </application>

</manifest>

1 个答案:

答案 0 :(得分:1)

您不清楚SplashScreen.java生活在哪个套餐中,但

android:name="info.androidhive.androidsplashscreentimer.SplashScreen"

可能需要更改为

android:name=".SplashScreen"

您可能刚刚从示例项目中粘贴了清单定义,而没有调整活动名称以匹配您自己的项目。