android启动画面无法正常工作

时间:2013-06-12 09:55:46

标签: android multithreading splash-screen

您好我在这里看到了一个教程(http://www.youtube.com/watch?v=embeFCPzRCg) 只有一个启动画面来,然后其他主屏幕来......视频中的代码工作正常......但是当我编码我自己时,日志猫和启动画面出现错误,但在进入下一个屏幕应用程序崩溃。

日志文件错误

块引用

06-12 14:34:45.195: I/dalvikvm-heap(25510): Grow heap (frag case) to 13.376MB for 519700-byte allocation

06-12 14:34:45.240: D/dalvikvm(25510): GC_CONCURRENT freed 1K, 8% free 12731K/13831K, paused 13ms+2ms, total 45ms

06-12 14:34:45.310: D/libEGL(25510): loaded /system/lib/egl/libEGL_mali.so

06-12 14:34:45.320: D/libEGL(25510): loaded /system/lib/egl/libGLESv1_CM_mali.so

06-12 14:34:45.325: D/libEGL(25510): loaded /system/lib/egl/libGLESv2_mali.so

06-12 14:34:45.325: D/(25510): Device driver API match

06-12 14:34:45.325: D/(25510): Device driver API version: 10

06-12 14:34:45.325: D/(25510): User space API version: 10 

06-12 14:34:45.325: D/(25510): mali: REVISION=Linux-r2p4-02rel0 BUILD_DATE=Tue Oct 16 
15:37:13 KST 2012 

06-12 14:34:45.365: D/OpenGLRenderer(25510): Enabling debug mode 0

06-12 14:34:46.275: W/dalvikvm(25510): threadid=11: thread exiting with uncaught exception (group=0x411292a0)

06-12 14:34:46.280: E/AndroidRuntime(25510): FATAL EXCEPTION: Thread-11666

06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml?

06-12 14:34:46.280: E/AndroidRuntime(25510):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)

06-12 14:34:46.280: E/AndroidRuntime(25510):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)

06-12 14:34:46.280: E/AndroidRuntime(25510):    at android.app.Activity.startActivityForResult(Activity.java:3446)

06-12 14:34:46.280: E/AndroidRuntime(25510):    at android.app.Activity.startActivityForResult(Activity.java:3407)

06-12 14:34:46.280: E/AndroidRuntime(25510):    at android.app.Activity.startActivity(Activity.java:3617)

06-12 14:34:46.280: E/AndroidRuntime(25510):    at android.app.Activity.startActivity(Activity.java:3585)

06-12 14:34:46.280: E/AndroidRuntime(25510):    at com.example.edoc_dc.Edoc_dc$1.run(Edoc_dc.java:28)

06-12 14:34:46.320: I/Process(25510): Sending signal. PID: 25510 SIG: 9
06-12 14:35:12.360: W/dalvikvm(25869): threadid=11: thread exiting with uncaught exception (group=0x411292a0)

06-12 14:35:12.360: E/AndroidRuntime(25869): FATAL EXCEPTION: Thread-11681

06-12 14:35:12.360: E/AndroidRuntime(25869): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml?

06-12 14:35:12.360: E/AndroidRuntime(25869):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1545)

06-12 14:35:12.360: E/AndroidRuntime(25869):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1420)

06-12 14:35:12.360: E/AndroidRuntime(25869):    at android.app.Activity.startActivityForResult(Activity.java:3446)

06-12 14:35:12.360: E/AndroidRuntime(25869):    at android.app.Activity.startActivityForResult(Activity.java:3407)

06-12 14:35:12.360: E/AndroidRuntime(25869):    at android.app.Activity.startActivity(Activity.java:3617)

06-12 14:35:12.360: E/AndroidRuntime(25869):    at android.app.Activity.startActivity(Activity.java:3585)

06-12 14:35:12.360: E/AndroidRuntime(25869):    at com.example.edoc_dc.Edoc_dc$1.run(Edoc_dc.java:28)

这是我的启动画面代码,首先加载到edoc_dc.java

  package com.example.edoc_dc;

  import android.os.Bundle;
  import android.app.Activity;
  import android.content.Intent;
  import android.view.Menu;
  import android.view.MenuItem;
  import android.support.v4.app.NavUtils;

  public class Edoc_dc extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_edoc_dc);


// meke the thread here

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

            try{
                sleep(1000);
            }catch(Exception e){
                e.printStackTrace();
            }finally{
                startActivity(new Intent( getApplicationContext(), Main.class));
                finish();
            }//end finaly

        }// end run

    };// end thread 

    splash_screen.start();

}// end method

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_edoc_dc, menu);
    return true;
}


 }

这是它的activity_edoc_dc.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:src="@drawable/ic_final" />

   </RelativeLayout>

这里是要加载的main.java package com.example.edoc_dc;

     import android.app.Activity;
     import android.os.Bundle;

     public class Main extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    // adding the desktop to it
    setContentView(R.layout.main_desktop);

}// end on create
   }// end main 

这是它的xml文件main_desktop.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

 <TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="HERE IS THE DESKTOP"
    android:textAppearance="?android:attr/textAppearanceSmall" />

   </LinearLayout>

这是我的清单文件

  <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.edoc_dc"
android:versionCode="1"
android:versionName="1.0" >

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

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name=".Edoc_dc"
        android:label="@string/title_activity_edoc_dc" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

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

  </manifest>

请解决问题并告诉该怎么做..应用程序运行良好刚刚崩溃到主屏幕之前

8 个答案:

答案 0 :(得分:3)

您尚未在清单文件

中为活动主目录创建条目
<activity
    android:name=".Main"
    android:label="@string/title_activity_edoc_dc" >   
</activity>

在线程中使用sleep不是一个好的设计。

如果您实施ThreadHandlerThread,请确保您的UI线程在等待工作线程完成时不会阻止 - do not call Thread.wait()Thread.sleep()

http://developer.android.com/training/articles/perf-anr.html

您可以使用处理程序

   private static final int SPLASH_TIME = 2 * 1000;// 3 seconds

处理程序

   new Handler().postDelayed(new Runnable() {

        public void run() {

          Intent intent = new Intent(Edoc_dc.this,Main.class);
            startActivity(intent);

           Edoc_dc.this.finish();
        }    

    }, SPLASH_TIME);

注意:有些人认为启动画面是邪恶的,特别是如果什么都不做(只是延迟)。

http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/

答案 1 :(得分:1)

你没有将你的文件Main.java声明为你的Manifest文件,就像这里的错误一样:

06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException:  
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml?

答案 2 :(得分:0)

06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml?

这看起来像是一个问题,请检查您的清单,让您使用正确的名称/包声明此活动

答案 3 :(得分:0)

正如LogCat所说,似乎您还没有在清单文件中声明您的活动“主”。

答案 4 :(得分:0)

错误写在logcat的所有字母中:

06-12 14:35:12.360: E/AndroidRuntime(25869): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml?
必须在AndroidManifest中定义

您应用的所有活动。您正在尝试显示不是

的活动Main

答案 5 :(得分:0)

你还没有在Manifest.thats中声明你的主要活动,为什么它会抛出ActivityNotFoundException。

声明这个 -

<activity
        android:name=".Main">

</activity> 

答案 6 :(得分:0)

答案在您的错误日志中:

"06-12 14:35:12.360: E/AndroidRuntime(25869): android.content.ActivityNotFoundException:
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main};
have you declared this activity in your AndroidManifest.xml?"

您必须在清单文件中添加此块:

<activity android:name="com.example.edoc_dc.Main"/>

之前&lt; / application&gt;标签

这是您主要活动的声明。

答案 7 :(得分:0)

你的logcat说明了一切:

06-12 14:34:46.280: E/AndroidRuntime(25510): android.content.ActivityNotFoundException: 
Unable to find explicit activity class {com.example.edoc_dc/com.example.edoc_dc.Main}; have you declared this activity in your AndroidManifest.xml?

尝试在清单中声明主要活动:

<activity android:name="com.example.edoc_dc.Main" </activity> 

另外:more info on splashscreens

另外:don't use splashscreens, it's an iOS thing :)

干杯,希望我帮忙。

相关问题