Question

I'm trying to make a Home Replacement app, but I'm running into a bunch of glitches. When the app launches for the first time, you go through several setup screens that allow you to configure basic settings. Once you are done with that, you get to the HomeScreen activity. In the AndroidManifest.xml I have included the following:

<activity android:name="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>

In the HomeScreen activity, I have included the following methods:

protected void onNewIntent(Intent intent) {
    super.onNewIntent(intent);
    if (Intent.ACTION_MAIN.equals(intent.getAction())) {
        getWindow().closeAllPanels();
    }
}
public void onDestroy() {
    super.onDestroy();
}

Also in the HomeScreen activity, I have a button that effectively exits the entire app. The associated code is:

public void exitApp(View view){
    this.finish();
    Intent intent = new Intent(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_HOME);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);
}

So basically what I want is that when you get to the HomeScreen activity the first time, a prompt comes up telling you to select your default Home Screen (this doesn't happen unless I press the Home Button, I want this to happen as soon as the activity is launched). Once I do set this as my default Home Screen, it works, but only fundamentally. Pressing the home button brings me back to this activity (as it should), but when I tap the Exit button, I don't get returned to the stock Home Launcher, which is what I want.

Was it helpful?

Solution

First, your Manifest is ok,
but in your exitApp you want to finish the activity, right?
in your code you finish it and then start it again..

Pressing the home button brings me back to this activity (as it should),
but when I tap the Exit button, I don't get returned to the stock Launcher,
which is what I want.

if a user had installed another home replacment app (e.g. Go Launcher Ex)
and if the user had set Go Launcher as default before defaulting to your app,
you want to return to Go Launcher Ex, right?
I assume yes.

This is partially possible,
what you can do is prompting the user which home launcher to use
after exiting your launcher:

import android.content.pm.PackageManager;

public void exitApp()
{
    //call this method to exit _CLEARLY_,
    //and prompt the user which launcher to use next

    //clear the default for your app (to show the prompt when exiting)
    final PackageManager pm = getPackageManager();
    pm.clearPackagePreferredActivities(getApplicationContext().getPackageName());

    //exit _CLEARLY_
    //calling finish(); would be ok also,
    //but there would stay a 'zombie' in the dalvik cache
    //and 'zombies' only use up your memory, so kill your entire app:
    android.os.Process.killProcess(android.os.Process.myPid());
}

So basically what I want is that when you get to the HomeScreen
activity the first time, a prompt comes up telling you to select your
default Home Screen (this doesn't happen unless I press the Home
Button, I want this to happen as soon as the activity is launched).

then call this function in onCreate(),
it simulates a homebutton press by calling an intent with Intent.CATEGORY_HOME:

public void showPrompt()
{
    Intent i = new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_HOME);
    startActivity(i);
}

Hope this is what you wanted

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top