m0skit0
m0skit0

Reputation: 25873

Launcher development - Home button not going back to initial activity

I have an app that acts as a Launcher. This app has 3 activities:

All activities are launched through startActivity, including the apps.

I want the standard Android Launcher behavior, that is: when entering an app through DashboardActivity, if I click home button, go to the main Launcher activity (LauncherActivity), and when clicking back, go to the dashboard (DashboardActivity).

The problem I have is that when clicking home, it goes back to DashboardActivity, not to LauncherActivity. If I finish DashboardActivity, then when clicking back on an app, it goes back to LauncherActivity.

Any ideas on how to solve this?

Upvotes: 6

Views: 1100

Answers (1)

Larry Schiefer
Larry Schiefer

Reputation: 15775

This is definitely back/task stack related. See this link for more information about the task stack.

When you go from LauncherActivity to DashboardActivity, the dashboard is placed on to the task stack. When the LauncherActivity is requested again via the HOME button, the task stack is restored back to the last Activity which was in use after launching the LauncherActivity, which was DashboardActivity.

You have several different options to resolve this:

  1. Don't use a separate Activity for the "dashboard". Consider a drawer or even a Fragment which shows the content and can be popped back to the main LauncherActivity when it is done calling startActivity to launch another app.
  2. After your DashboardActivity calls startActivity, it should call finish() so it will get popped off the current task stack.
  3. Usually launchers are setup to be launched in singleInstance mode, preventing multiple instances of the launcher Activity to run at the same time. Note that you'll need to support onNewIntent in your LauncherActivity.
  4. To prevent odd interactions with the task manager, consider setting FLAG_ACTIVITY_NO_HISTORY when launcher your DashboardActivity.

Upvotes: 2

Related Questions