0

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?

TronicZomB
  • 8,667
  • 7
  • 35
  • 50
scibor
  • 983
  • 4
  • 12
  • 21

2 Answers2

1

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);
JRaymond
  • 11,625
  • 5
  • 37
  • 40
  • This is definitely the way I want to go, it seems like it's almost working, the only problem I get is that when I tap the Exit button, I get a dialog box that shows "Launcher" and then "No apps can perform this action"; can you maybe expand a little on the code? – scibor Jul 01 '13 at 15:57
  • Yes! The exit mechanism works perfectly, I'm still having a little trouble making this the default home screen but will mess around with the code myself and maybe put up a question later. Thank you, this was very helpful – scibor Jul 01 '13 at 16:05
0

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

Jscti
  • 14,096
  • 4
  • 62
  • 87