Switching between activities
Often we will want to activate one activity from within another activity. Although this is not a difficult task, it will require a little more setting up to be done than the previous recipes as it requires two activities. We will create two activity classes and declare them both in the manifest. We'll also create a button, as we did in the previous recipe, to switch to the activity.
Getting ready
We'll create a new project in Android Studio, just as we did in the previous recipes, and call this one ActivitySwitcher
. Android Studio will create the first activity, ActivityMain
, and automatically declare it in the manifest.
How to do it...
- Since the Android Studio New Project wizard has already created the first activity, ...
Get Android Application Development Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.