0

我的应用程序似乎可以正常启动,并带有启动画面和其他东西。但是当它休眠 6 秒并且它应该进入主要活动时,应用程序崩溃了,请问有什么帮助吗?

这是我的代码(android.intent.action1.MAINACTIVIVTY,“action”被故意更改为“action1”)

package com.hellhogone.multitools;

import com.hellhogone.multitools.R;

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

public class Splash extends Activity{

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 
    setContentView(R.layout.splash);

    MediaPlayer yo = MediaPlayer.create(Splash.this, R.raw.smusic); 
    yo.start(); 

    Thread timer = new Thread(){
        public void run(){
            try{
                sleep(6000);
            }catch(InterruptedException e){
                e.printStackTrace();
            }finally{
                Intent h1 = new Intent("android.intent.action1.MAINACTIVITY");
                startActivity(h1); 
            }
        }
    };

    timer.start(); 
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    finish(); 
}



}
4

1 回答 1

1

您不能从 UI 线程以外的其他线程启动活动。为避免此问题,您可以使用runOnUiThread()

    }finally{
        runOnUiThread(new Runnable() {
            public void run() {
                Intent h1 = new Intent("android.intent.action1.MAINACTIVITY");
                startActivity(h1);
            }
        });
    }
于 2013-04-13T18:26:51.507 回答