Question: I have an activity with launch mode as Single Task.The activity is launched by with intent flags Intent.FLAG\_ACTIVITY\_NEW\_TASK by a Broadcast receiver . If this activity is on top of home screen and if I call moveTasktoBack(true) from this activity, I expect the home screen to be shown however instead of home screen, Activity B from another task is brought in front. The sequence of operations is as follow. 

Activity B in TASK B -> [Press Home Button] -> Home Screen -> Launch Activity A by BroadCast Receiver -> Activity A calls moveTaskToBack(true) -> Activity B in Task B comes to foreground.

I have checked the Task Affinity of Task A (with activity A) and Task B (with activity B) and they are different. 

How can I make sure that in such a scenario, Home screen is shown when activity moves itself to back of stack.

Answer: 
It seems that problem is here:

```
Road width, length, depth, asphalt, output;

/// Some code

width.set_road_width(inputWidth);
length.set_road_length(inputLength);
depth.set_road_depth(inputDepth);
asphalt.asphalt_required();

```

and how it could be

```
Road output;

/// Some code

output.set_road_width(inputWidth);
output.set_road_length(inputLength);
output.set_road_depth(inputDepth);
output.asphalt_required();

```

That would help you.

This is because you create one instance of class where you already have everything for your calculations. In this situation that might be better to have everything you need in your constructor, like this:

```
class Road
{
public:
   Road(double width, double length, double depth)
   double asphalt_required();
private:
   double roadDepth;
   double roadWidth;
   double roadLength;
   double roadAsphalt;
};

Road::Road(double width, double length, double depth)
 : roadDepth(depth)
 , roadWidth(width)
 , roadLength(length) {
}

/// Other code...

```

This is better, because it could also prevent you from such errors. Everything that you would need to do is do some modification

```
double inputWidth = 0.0, inputLength = 0.0, inputDepth = 0.0;

/// Here we got all needed values...

Road output(inputWidth, inputLength, inputDepth);
output.asphalt_required();

/// And then output...

```
You never do anything with `output` other than construct it and print its `asphalt_required()`. This is why it prints zero: you never actually modify `output` in any way!

Beyond that, you may want to think about why you construct so many `Road` instances. It seems like there should be only one. As it stands, you have five `Road`s: three are one-dimensional and two are zero-dimensional.