Now that we have a Timeline activity, we need to give it an options menu, just as we did for our Status activity in The Options Menu. This is especially important because the Timeline activity is the entry point into our application, and without the menu, the user cannot easily get to any other activity or start and stop the service.
As one approach, we could copy and paste the code we already have from the Status activity, but that’s rarely a good strategy. Instead, we’ll do what we usually do: refactor the code. In this case, we can take out the common functionality from the Status activity and place it in another activity that will serve as the base. See Figure 10-2.
Figure 10-2. BaseActivity refactor
To do that, we’ll create a
new class called
move the common functionality into it. For us, the common functionality
includes getting the reference to the
object, as well as the
methods that support the options menu.
While we’re at it, instead of having Start Service and
Stop Service menu buttons, it would be nice to provide just one button
that toggles between Start and Stop. To do that, we’ll change our menu
onMenuOpened() to the
base activity to dynamically update the title and images for this
First, we’ll update the menu.xml file to include our new toggle ...