【问题标题】:Splash screen won't display before main actvity在主要活动之前不会显示启动画面
【发布时间】:2013-05-26 19:47:43
【问题描述】:

我正在开发一个 android 应用程序,但似乎无法在主要活动之前启动启动画面,但在我所有其他应用程序上这都没问题

这可能是什么问题?代码没有问题。

package com.example.soundboardapp;



import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;

public class splash extends Activity {
    private long ms = 0;
    private long splashTime = 2000;
    private boolean splashActive = true;
    private boolean paused = false;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        this.requestWindowFeature(Window.FEATURE_NO_TITLE);

        setContentView(R.layout.splash);

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

                try {
                    while (splashActive && ms < splashTime) {
                        if (!paused)
                            ms = ms + 100;
                        sleep(100);
                    }
                } catch (Exception e) {
                } finally {

                    Intent intent = new Intent(splash.this, MainActivity.class);
                    finish();
                    startActivity(intent);
                }
            }
        };
        mythread.start();
    }
}

有一个与代码对应的启动活动。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/intro22"
     >

    <LinearLayout
        android:id="@+id/linearLayout1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:gravity="center" >



    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="184dp" />

</RelativeLayout>

可能是什么问题?

【问题讨论】:

  • cyrilmottier.com/2012/05/03/…。有些人不鼓励启动画面
  • 你的启动画面也没有任何作用,你为什么要拥有它?
  • 我寻求帮助以使其正常工作,而不是让别人告诉不要使用它...
  • 请发布您的 AndroidManifest.xml
  • @GeoffBolton 检查链接。使用处理程序的启动画面。stackoverflow.com/questions/16750059/…

标签: java android xml splash-screen


【解决方案1】:

我猜您没有将splash 活动设置为应用程序的启动活动。如果您有类似的内容,请检查 AndroidManifest.xml 文件:

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

让我知道这是否是问题所在。

【讨论】:

    【解决方案2】:

    你不应该使用线程, 而不是整个线程,使用这个:

    new Handler().postDelayed(new Runnable() {
     public void run() {
                        Intent intent = new Intent(splash.this, MainActivity.class);
                        finish();
                        startActivity(intent);
    
    }, splashTime);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 2019-03-31
      • 1970-01-01
      相关资源
      最近更新 更多