我在Android Studio上制作的应用程序有问题。我不知道为什么,但是在启动屏幕之后,应用程序崩溃了。我希望在初始屏幕之后打开 Activity “Accueil”。上周工作正常,但现在不行了。我什么都没碰。我向您展示清单和.java文件。

Splashscreen.java:

import android.app.Activity;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.os.Bundle;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class Splashscreen extends Activity {
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
        Window window = getWindow();
        window.setFormat(PixelFormat.RGBA_8888);
    }

    Thread splashTread;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_splashscreen);
        StartAnimations();
        Thread loading = new Thread() {
            public void run() {
                try {
                    sleep(5000);
                    Intent main = new Intent(Splashscreen.this,Menu.class);
                    startActivity(main);
                    finish();
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                    finish();
                }
            }
        };

        loading.start();
    }

    private void StartAnimations() {
        Animation anim = AnimationUtils.loadAnimation(this, R.anim.alpha);
        anim.reset();
        LinearLayout l = (LinearLayout) findViewById(R.id.lin_lay);
        l.clearAnimation();
        l.startAnimation(anim);
        anim = AnimationUtils.loadAnimation(this, R.anim.rotate);
        anim.reset();
        ImageView iv = (ImageView) findViewById(R.id.splash);
        iv.clearAnimation();
        iv.startAnimation(anim);
        splashTread = new Thread() {
            @Override
            public void run() {
                try {
                    int waited = 0;

                    while (waited < 3500) {
                        sleep(100);
                        waited += 100;
                    }

                    Intent intent = new Intent(Splashscreen.this,Menu.class);
                    startActivity(intent);
                    finish();
                } catch (InterruptedException e) {

                }
            }
        };
    }
}

Android清单:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.thibaudmangeot.erdfapplicationsecurite">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <activity android:name=".Splashscreen"
            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=".Accueil"
            android:label="@string/title_activity_accueil"/>
    </application>
</manifest>

Accueil.java:
package com.example.thibaudmangeot.erdfapplicationsecurite;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.widget.Button;
import android.view.View;

public class Accueil extends ActionBarActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_accueil);

        Button buttonfis = (Button) findViewById(R.id.buttonfis);

        buttonfis.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goTosignin();
            }
        });
    }

    private void goTosignin() {
        Intent intent = new Intent(this, Menu.class);
        startActivity(intent);
    }
}

最佳答案

做这个

Intent main = new Intent(Splashscreen.this, Accueil.class);
                    startActivity(main);
                     finish();

代替
Intent main = new Intent(Splashscreen.this, Menu.class);
                startActivity(main);
                finish();

您甚至没有在清单中提到菜单 Activity 。

07-24 09:48
查看更多