2016-11-11 7 views
1

アンドロイドアプリケーションを開発しており、マニフェストファイルでカテゴリタグを使用せずに実行時にランチャーとして起動したいと考えています。実行時にアンドロイドでランチャーとしてアプリケーションを設定する方法は?

<activity 
     android:name="com.sample.test.MainActivity" 
     android:configChanges="keyboardHidden|orientation|screenSize" 
     android:label="@string/title_activity_main" 
     android:theme="@style/AppTheme" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
</activity> 
+0

あなたはここに参照することができますhttp://stackoverflow.com/questions/7414272/how-to-launch-an-android-app-without-android-intent-category-launcher – Raju

答えて

1

あなたが望むように直接行う方法はありません。ランチャーアクティビティを設定するには、マニフェストを編集する必要があります。実際には実行できません。それは以前に保存したアクティビティの名前を読んでのonCreate()メソッドだと、あなたが本当にアプリをクリックして起動する必要があり

<activity 
     android:name="com.sample.test.LauncherActivity" 
     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> 

内側:
しかし、あなたが何ができるかは、このインテントフィルタを使用してマニフェストの一部LauncherActivityを宣言することですアイコンをSharedPreferencesから選択して起動します。このように:

public class LauncherActivity extends Activity { 
    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     String activityToLaunch = getSharedPreferences("LauncherActivity", MODE_PRIVATE).getString("LauncherActivity", "Some default Activity"); 
     Intent intent; 
     switch (activityToLaunch) { 
      case "SomeActivity1": 
       intent = new Intent(this, SomeActivity1.class); 
       break; 
      case "SomeActivity2": 
       intent = new Intent(this, SomeActivity2.class); 
       break; 
      case "SomeActivity3": 
       intent = new Intent(this, SomeActivity3.class); 
       break; 
      default: 
       intent = new Intent(this, SomeDefaultActivity.class); 
       break; 
     } 
     startActivity(intent); 
     finish(); 
    } 
} 
関連する問題