我需要在某个时间段后从当前活动开始一项活动。我编码如下。
public class FirstActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_first);
new Timer().schedule(new TimerTask(){
public void run() {
startActivity(new Intent(FirstActivity.this, SecondActivity.class));
}
}, 2000);
}
但它不起作用..它一直在崩溃..我的方法正确吗?我的清单文件如下
`
<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=".FirstActivity"
android:label="@string/title_activity_first" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SecondActivity"
android:label="@string/title_activity_second" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="com.example.first.FirstActivity" />
</activity>
</application>