我的應用中要用到線程和intent,但是應用運行不起來。
也沒有任何警告和報錯。
Manifest代碼:
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.example.learn.tam.Splash"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.example.learn.tam.StartingPoint"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
Activity代碼:
package com.example.learn.tam;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
public class Splash extends Activity{
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Thread timer = new Thread(){
public void run(){
try {
sleep(5000);
}
catch (InterruptedException e){
e.printStackTrace();
}
finally{
Intent openStartingPoint = new Intent("com.example.learn.tam.StartingPoint");
startActivity(openStartingPoint);
}
}
};
timer.start();
}
}
請高手指點一下,謝謝。
是activity的Intent-filter配置錯了。
如果是系統默認系統的activity,應該這樣配置:
<activity
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SPLASH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
如果是普通的activity,應該這樣配置:
<activity
android:name="com.example.learn.tam.StartingPoint"
android:label="@string/app_name" >
<intent-filter>
<action android:name="com.example.learn.tam.StartingPoint" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
其實你的代碼這樣寫也是可以的:
Intent openStartingPoint = new Intent(Splash.this, StartingPoint.class);
startActivity(openStartingPoint);