문제

I want an application that acts as a Home Replacement app. There are several activities when you first launch the app that allow you to configure basic settings. Then you get to the Home Screen. In the Android Manifest, I have added the following lines:

    <activity android:name="com.tabletnanny.HomeScreenMain"
        android:theme="@style/Theme"
        android:launchMode="singleInstance"
        android:stateNotNeeded="true">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.HOME"/>
        <category android:name="android.intent.category.DEFAULT" />
    </intent-filter>
    </activity>

Now what I want is the following: every time that the user gets to this activity, the box that prompts you which home screen you want to set as default pops up. This has to pop up no matter what every time the app is launched, even if during a previous launch, the user accidentally selected the wrong Home Screen "Always". I also have an "Exit" button on this Home Screen. Tapping the "Exit" button will bring up this dialog box once again and allow you to select the default Home Screen again. How can I do this in the java code?

도움이 되었습니까?

해결책

Android makes this pretty easy - just build up an intent for launching home like so:

Intent home = new Intent(Intent.ACTION_MAIN);
home.addCategory(Intent.CATEGORY_HOME);

Intent has a method that generates a "Chooser" Intent. the chooser intent launches a dialog showing all Activitys that can respond to the intent you created; in your case the "Home" category:

Intent chooser = Intent.createChooser(home, "Launcher");
mContext.startActivity(chooser);

다른 팁

I don't think you can force the system to forget the user preference. Once the user preference is stored, it will only come back if an application gets updated or you install a new Launcher.

But you can force an intent you fire yourself to display the App chooser (solution for your "Exit" button) : see http://developer.android.com/training/basics/intents/sending.html#AppChooser

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