Android Programming The Big Nerd Ranch Guide by Bill Phillips, Chris Stewart, Kristin Marsicano (z-lib.org)

(gtxtreme123) #1
Starting a new task

This will not do. Instead, you want NerdLauncher to start activities in new tasks (Figure 24.10). That
way each application opened by pressing an item in the NerdLauncher list gets its own task, which
will allow users to switch between running applications via the overview screen, NerdLauncher, or the
Home screen, as they prefer.


Figure 24.10  Launching CriminalIntent into its own task


To start a new task when you start a new activity, add a flag to the intent in
NerdLauncherFragment.java.


Listing 24.9  Adding new task flag to intent (NerdLauncherFragment.java)


public class NerdLauncherFragment extends Fragment {
...
private class ActivityHolder extends RecyclerView.ViewHolder
implements View.OnClickListener {
...
@Override
public void onClick(View v) {
...
Intent i = new Intent(Intent.ACTION_MAIN)
.setClassName(activityInfo.applicationInfo.packageName,
activityInfo.name)
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);


startActivity(i);
}
}
...
}

Free download pdf