为什么我的Android应用程序不会打开/启动?

时间:2013-02-13 22:25:46

标签: android

当有人从应用程序商店安装我的应用程序时,打开按钮(通常在安装完成后在卸载按钮旁边找到)显示为灰色,并且在他们的应用程序抽屉中找不到该应用程序。

此外,当我从Eclipse执行选择Default Activity时,它在控制台中说它安装了APK,但它没有启动。如果我选择Splash活动作为运行配置中的默认活动,它会毫无障碍地运行,但我之后仍然无法在我的应用程序抽屉中找到它。帮助将不胜感激c:

清单:           

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="17" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.meteorfiber.gangnamstyle.Splash"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="com.meteorfiber.gangnamstyle.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name="com.meteorfiber.gangnamstyle.MainActivity"
        android:configChanges="keyboardHidden|orientation|screenSize"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
        <intent-filter>
            <action android:name="com.meteorfiber.gangnamstyle.MAINACTIVITY" />

            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
    </activity>
</application>

</manifest>

飞溅:

package com.meteorfiber.gangnamstyle;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.preference.PreferenceManager;

public class Splash extends Activity {

private final int SPLASH_DISPLAY_LENGTH = 3000;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.splash);
}

@Override
protected void onResume() {
    super.onResume();
    SharedPreferences sp = PreferenceManager
            .getDefaultSharedPreferences(this);

    boolean isSplashEnabled = sp.getBoolean("isSplashEnabled", true);

    if (isSplashEnabled) {
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {

                Splash.this.finish();

                Intent mainIntent = new Intent(Splash.this,
                        MainActivity.class);
                Splash.this.startActivity(mainIntent);
            }
        }, SPLASH_DISPLAY_LENGTH);
    } else {

        finish();
        Intent mainIntent = new Intent(Splash.this, MainActivity.class);
        Splash.this.startActivity(mainIntent);
    }
}
 }

MainActivity:

package com.meteorfiber.gangnamstyle;


import android.app.Activity;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.view.WindowManager;

public class MainActivity extends Activity {

    MediaPlayer ourSong;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_FULLSCREEN);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(new GameView(this));
    ourSong = MediaPlayer.create(MainActivity.this, R.raw.song);
    ourSong.start();
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {
        // preventing default implementation previous to
        // android.os.Build.VERSION_CODES.ECLAIR
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

@Override
protected void onPause() {
    // TODO Auto-generated method stub
    super.onPause();
    ourSong.release();
}

}

1 个答案:

答案 0 :(得分:1)

将您的启动活动的意图过滤器更改为

<intent-filter>
    <action android:name="android.intent.action.MAIN" />
    <category android:name="android.intent.category.LAUNCHER" />
</intent-filter>

Android启动器以及设置活动尝试在您的应用程序中找到此intent-filter以启动活动。如果找不到,则无法使用典型的启动器启动您的活动,并且不会显示。