문제

I'm creating a cool Home application in Android.

As this is a Home app I don't want her to appear in the Launcher, in the list of all applications.

That's pretty easy, but now I would like the settings of this application to appear. So, I created the preferences of my application this way in the Manifest:

<activity android:name=".Preferences" android:label="@string/application_name">
<intent-filter>
       <action android:name="android.intent.action.MAIN" />
       <category android:name="android.intent.category.LAUNCHER" />
 </intent-filter>
</activity>

That work pretty well and I have an extra icon in the Launcher!

The only problem is that nothing happens when I click on the Icon. Therefore, I can launch my Preferences from within the application:

final Intent preferences = new Intent(Launcher.this,Preferences.class);        
menu.add(0, MENU_PREFERENCES, 0, R.string.application_name).setIcon(
        R.drawable.ic_menu_preferences).setAlphabeticShortcut('F').setIntent(
          preferences);

So, why is the shortcut in the launcher totally useless and does not launch anything?

More informations here:

Log when I launch from within the application (preferences are launched, worked flawlessly):

08-25 13:13:03.009: INFO/ActivityManager(63): Starting activity: Intent { cmp=com.myapp.home/.Preferences }

When I launch from the launcher (nothing happens):

08-25 13:13:45.489: INFO/ActivityManager(63): Starting activity: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.myapp.home/.Preferences }

My activity:

public class Preferences extends PreferenceActivity {

 @Override
 protected void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  addPreferencesFromResource(R.xml.preferences);

 }
}
도움이 되었습니까?

해결책

Just found something! (And btw, what is the best procedure to use when I found an answer to my own question? Should I answer myself? here..)

I had to use that in Manifest:

      <activity android:clearTaskOnLaunch="true" android:launchMode="singleTask" android:stateNotNeeded="true" (...other parameters...)>

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

That work pretty well!

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top