0
<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 活动节点处生成警告:“导出的活动不需要权限”

任何人都可以说发生了什么吗?

4

2 回答 2

1

在 Manifast.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);
于 2012-07-05T12:42:47.203 回答
1

在 Manifast.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();
    }
}
于 2012-07-05T12:50:13.933 回答