我的主要活动和启动画面有问题。有意图过滤它们
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
当我从MainActivity中删除intent-filter时,app无法打开。我该怎么办?
答案 0 :(得分:2)
的AndroidManifest.xml
<activity
android:name="com.example.SplashScreen"
android:label="@string/app_name"
android:screenOrientation="portrait"
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.example.MainActivity"
android:label="@string/app_name" >
</activity>
SplashScreen类
public class SplashScreen extends Activity {
private static int SPLASH_TIME_OUT = 3000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(SplashScreen.this, MainActivity.class);
startActivity(i);
finish();
}
}, SPLASH_TIME_OUT);
}
}
主要活动类
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
答案 1 :(得分:1)
您只需要为启动画面设置意图过滤器。您需要从启动画面活动开始主要活动。
清单
<activity android:name="com.example.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.example.MainActivity"></activity>
从启动画面启动主要活动并完成
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();