<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.app.android"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="15" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.StyledCustom" >
<activity
android:name=".SplashActivity"
android:label="@string/title_activity_main"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/Theme.StyledCustom" >
<intent-filter>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
</manifest>
我包含了SplashActivity.java(我正在使用ActionBarSherlock):
package com.app.android;
import com.app.android.R;
import android.content.Intent;
import android.os.Bundle;
import com.actionbarsherlock.app.SherlockActivity;
public class SplashActivity extends SherlockActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
getSupportActionBar().hide();
Thread timerSplash = new Thread(){
@Override
public void run() {
try{
int i = 0;
while(i < 1000){
i+=100;
sleep(100);
}
startActivity(new Intent("com.app.android.MainActivity"));
}catch(Exception ex){
}finally{
finish();
}
}
};
timerSplash.start();
}
}
我面临的是我的MainActivity在SplashActivity之前推出。 此外,AndroidManifest.xml中的MainActivity活动节点也会生成警告:“导出的活动不需要权限”
任何人都能说出现在发生了什么吗?
答案 0 :(得分:1)
在Manifest.xml中定义Activity:
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/Theme.StyledCustom" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
并以:
开头Intent intent = new Intent();
intent.setComponent(new ComponentName("com.app.android", "com.app.android.MainActivity"));
startActivity(intent);
答案 1 :(得分:1)
在Manifest.xml中:
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main"
android:theme="@style/Theme.StyledCustom" >
</activity>
和下面的课程
public class SplashActivity extends SherlockActivity{
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
getSupportActionBar().hide();
Thread timerSplash = new Thread(){
@Override
public void run() {
try{
int i = 0;
while(i < 1000){
i+=100;
sleep(100);
}
Intent intent = new Intent(SplashActivity.this, MainActivity.class);
startActivity(intent);
}catch(Exception ex){
}finally{
finish();
}
}
};
timerSplash.start();
}
}