早先我使用以下代碼是工作:如何實現初始屏幕中類擴展片段
package com.usd.quiztest;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
public class Logo extends Activity
{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.logo_screen);
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 5 seconds
sleep(2000);
// After 5 seconds redirect to another intent
Intent i=new Intent(getBaseContext(),First.class);
startActivity(i);
//Remove activity
finish();
} catch (Exception e) {
}
}
};
// start thread
background.start();
}
}
但是當我使用此代碼insted的上述代碼(類擴展活動/類擴展片段)
package com.usd.quiztest;
import android.support.v4.app.Fragment;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Logo extends Fragment{
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState){
return inflater.inflate(R.layout.logo_screen, null);
}
public void onActivityCreated(Bundle savedInstanceState){
super.onActivityCreated(savedInstanceState);
Thread background = new Thread() {
public void run() {
try {
// Thread will sleep for 5 seconds
sleep(2000);
// After 5 seconds redirect to another intent
Intent i=new Intent(getBaseContext(),First.class);
startActivity(i);
//Remove activity
finish();
} catch (Exception e) {
}
}
};
// start thread
background.start();
}
}
我的應用程序端了幸運停止錯誤
幫我實現閃屏類擴展片段
錯誤:
Description Resource Path Location Type
Intent cannot be resolved to a type Logo.java /QuizTest/src/com/usd/quiztest line 25 Java Problem
Description Resource Path Location Type
Intent cannot be resolved to a type Logo.java /QuizTest/src/com/usd/quiztest line 25 Java Problem
Description Resource Path Location Type
The method finish() is undefined for the type new Thread(){} Logo.java /QuizTest/src/com/usd/quiztest line 29 Java Problem
Description Resource Path Location Type
The method getBaseContext() is undefined for the type new Thread(){} Logo.java /QuizTest/src/com/usd/quiztest line 25 Java Problem
AndroidManifest.xml中
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.usd.quiztest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="16" />
<supports-screens>
android:resizeable="true"
android:smallScreens="true"
android:normalScreens="true"
android:largeScreens="true"
android:xlargeScreens="true"
android:anyDensity="true"
</supports-screens>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.usd.quiztest.Logo"
android:label="@string/app_name"
android:theme="@android:style/Theme.Black.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name="com.usd.quiztest.First"
android:label="@string/app_name"
android:clearTaskOnLaunch="true" >
</activity>
<activity
android:name="com.usd.quiztest.Q1"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.usd.quiztest.Q2"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.usd.quiztest.Q3"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.usd.quiztest.Q4"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.usd.quiztest.Q5"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.usd.quiztest.FinalPage"
android:label="@string/app_name" >
</activity>
<activity
android:name="com.usd.quiztest.Score"
android:label="@string/app_name" >
</activity>
</application>
</manifest>
請發佈您的logcat – Lal
你不應該使用啓動畫面它不是一個好主意http://cyrilmottier.com/2012/05/03/splash-screens-are-evil-dont-use-them/ – Raghunandan
哪裏有你添加你的片段和它被添加到什麼? 發佈一些更多的代碼和你得到的錯誤 – elmorabea