Android异步任务 - 找不到处理意图的活动

时间:2012-09-24 21:05:10

标签: android android-intent android-asynctask

我正在使用异步任务来创建加载屏幕,但是当我想将意图传递给主要活动时,应用程序崩溃...这里有一些代码:

 public class StartActivity extends Activity {
     protected boolean _active = true;
     protected int _splashTime = 5000;

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

    Thread splashThread = new Thread() {
        @Override
        public void run(){
            try {
                int waited = 0;
                while(_active && (waited <_splashTime)) {
                    sleep(100);
                    if(_active) {
                        waited +=100;
                    }
                }
            } catch(InterruptedException e) { 
            } finally {

                startActivity(new Intent("HNappActivity"));
                finish();

            }
        }
    };
    splashThread.start();
    }

这里的清单:

  <activity
        android:name=".StartActivity"
        android:label="@string/title_activity_hnapp" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="HNappActivity"></activity>

logcat的:

  09-24 20:47:06.841: E/AndroidRuntime(556): FATAL EXCEPTION: Thread-10
  09-24 20:47:06.841: E/AndroidRuntime(556): android.content.ActivityNotFoundException: No Activity found to handle Intent { act=HNappActivity }
  09-24 20:47:06.841: E/AndroidRuntime(556):    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1409)
  09-24 20:47:06.841: E/AndroidRuntime(556):    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1379)
  09-24 20:47:06.841: E/AndroidRuntime(556):    at android.app.Activity.startActivityForResult(Activity.java:2827)
  09-24 20:47:06.841: E/AndroidRuntime(556):    at android.app.Activity.startActivity(Activity.java:2933)
  09-24 20:47:06.841: E/AndroidRuntime(556):    at sk.ecopress.hn.android.StartActivity$1.run(StartActivity.java:37)

首先启动StartActivity类,它显示加载屏幕,然后它应该将意图传递给主要活动,但它会崩溃。

2 个答案:

答案 0 :(得分:1)

您需要更改:

    startActivity(new Intent("HNappActivity")); 

为:

    startActivity(new Intent(StartActivity.this, HNappActivity.class));

此项活动必须存在于您正在考虑的项目中。

答案 1 :(得分:0)

更改

<activity android:name="HNappActivity"></activity>

 <activity android:name=".HNappActivity"></activity>

班级名称之前的点。

正如他们所说,你必须使用

来调用活动
  startActivity(new Intent(StartActivity.this, HNappActivity.class));