Android Studios Splash Screen停止播放

时间:2017-05-21 04:45:06

标签: android-studio splash-screen

每次运行模拟器并运行应用程序时,我都会遇到Android工作室启动画面的问题,它会在启动画面后停止。我的SplashScreen.java代码从我从别人那里看到的看起来很好。我相信问题在于清单,但似乎无法弄明白。 logcat没有显示任何问题。我被卡住了,所以任何帮助都会受到赞赏。

?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.mook.bodyshop">

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="Don's Body Shop"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".SplashScreen">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="com.example.mook.bodyshop.MainActivity"></activity>
</application>

这就是清单。这是SplashScreen.java

import java.util.Timer;
import java.util.TimerTask;

public class SplashScreen extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash_screen);
/*Thread myThread = new Thread(){
    @Override
    public void run() {
        try {
            sleep(1000);
            Intent intent = new Intent(SplashScreen.this, MainActivity.class);
            startActivity(intent);
            finish();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

};
    myThread.start();*/
    TimerTask task = new TimerTask() {
        @Override
        public void run() {

            startActivity(new Intent(SplashScreen.this, MainActivity.class));
            finish();
        }
    };
    Timer opening = new Timer();
    opening.schedule(task, 5000);
}
}

然后这是我的MainActivity.java

package com.example.mook.bodyshop;

import android.os.Bundle;  
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                    .setAction("Action", null).show();
        }
    });
}

@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_main, 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);
}
}

最后是logcat。

05-20 20:55:56.809 2826-2826/? I/art: Not late-enabling -Xcheck:jni (already on)
05-20 20:55:56.811 2826-2826/com.example.mook.bodyshop W/art: Unexpected CPU variant for X86 using defaults: x86
05-20 20:55:56.912 2826-2826/com.example.mook.bodyshop W/System: ClassLoader referenced unknown path: /data/app/com.example.mook.bodyshop-1/lib/x86
05-20 20:55:56.918 2826-2826/com.example.mook.bodyshop I/InstantRun: Starting Instant Run Server for com.example.mook.bodyshop
05-20 20:56:00.049 2826-2826/com.example.mook.bodyshop W/art: Before Android 4.1, method android.graphics.PorterDuffColorFilter android.support.graphics.drawable.VectorDrawableCompat.updateTintFilter(android.graphics.PorterDuffColorFilter, android.content.res.ColorStateList, android.graphics.PorterDuff$Mode) would have incorrectly overridden the package-private method in android.graphics.drawable.Drawable
05-20 20:56:00.706 2826-2900/com.example.mook.bodyshop I/OpenGLRenderer: Initialized EGL, version 1.4
05-20 20:56:00.706 2826-2900/com.example.mook.bodyshop D/OpenGLRenderer: Swap behavior 1
05-20 20:56:00.789 2826-2900/com.example.mook.bodyshop E/EGL_emulation: tid 2900: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
05-20 20:56:00.789 2826-2900/com.example.mook.bodyshop W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xafdf71e0, error=EGL_BAD_MATCH
05-20 20:56:01.107 2826-2826/com.example.mook.bodyshop W/art: Before Android 4.1, method int android.support.v7.widget.ListViewCompat.lookForSelectablePosition(int, boolean) would have incorrectly overridden the package-private method in android.widget.ListView
05-20 20:57:24.514 2826-2900/com.example.mook.bodyshop E/EGL_emulation: tid 2900: eglSurfaceAttrib(1174): error 0x3009 (EGL_BAD_MATCH)
05-20 20:57:24.514 2826-2900/com.example.mook.bodyshop W/OpenGLRenderer: Failed to set EGL_SWAP_BEHAVIOR on surface 0xafdf71c0, error=EGL_BAD_MATCH
05-20 20:57:32.689 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 6.473ms
05-20 20:58:13.809 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 5.264ms
05-20 21:02:05.962 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 10.112ms
05-20 21:02:14.501 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 11.953ms
05-20 21:02:33.544 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 5.971ms
05-20 21:09:03.525 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 7.841ms
05-20 21:09:14.570 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 10.387ms
05-20 21:09:25.601 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 16.057ms
05-20 21:10:55.477 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 6.419ms
05-20 21:11:00.001 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 13.669ms
 05-20 21:11:08.070 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 9.188ms
 05-20 21:13:12.125 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 23.024ms
 05-20 21:13:58.779 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 9.147ms
 05-20 21:14:12.845 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 10.171ms
 05-20 21:14:18.850 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 5.055ms
 05-20 21:15:02.487 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 6.034ms
 05-20 21:15:54.662 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 14.200ms
 05-20 21:16:02.691 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 15.037ms
 05-20 21:16:24.743 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 5.166ms
 05-20 21:18:55.781 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 8.182ms
 05-20 21:18:56.781 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 7.999ms
 05-20 21:19:55.990 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 7.446ms
 05-20 21:20:41.639 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 9.632ms
 05-20 21:21:59.857 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 9.553ms
 05-20 21:22:54.563 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 5.610ms
 05-20 21:22:57.065 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 5.631ms
 05-20 21:24:22.929 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 33.581ms
 05-20 21:24:47.231 2826-2833/com.example.mook.bodyshop W/art: Suspending all threads took: 13.339ms

1 个答案:

答案 0 :(得分:0)

我只是回答我自己的问题!问题是SplashScreen的扩展程度与MainActivity不同。

public class SplashScreen extends Activity
public class MainActivity extends AppCompatActivity

因此我将它们都延伸Activity,因为当我延长AppCompatActivity时,它仍然会在SplashScreen之后停止。