Sunday, March 17, 2013

How to create more then one activities with Android

Hi there! In this post i wanna show you how to create more activities in your Android App. Although seemingly simple, to create and use more than one activity is necessary to observe some details so that everything works as desirable.

To create a new activity, other than the main activity, it is necessary to follow the following steps(in this sequence):
  • create a new class that extends Activity
  • add it to the Manifest
  • create a new layout for it
  • if necessary, add new strings to name it. 

 

Create a new Activity

Create a new class by pressing Ctrl+N or by clicking the "class-icon" in eclipse and name is as you want. Make sure you extend it from Activity as shown bellow:





Add it to the manifest file

Locate you Android Manifest file and look for the tab Application. As shown in the picture bellow press add and browse the new class you've created.







Creating a new layout

Locate the folder layout, press the icon "new xml file" as shown bellow and add a new layout xml file selecting the type you may need. In my case it was a new xml file with RelativeLayout. 







Creating new Strings

If you need or want to, you may create some new strings to ensure internationalization. This is up to you. I recommend to do it from the beginning, as i did in this example. The new string can be used in the Manifest file as i did while browsing the new created file as you can see bellow. (See point 4. in the picture bellow)




😱👇 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘‡

Be sure to read, it will change your life!
Show your work by Austin Kleonhttps://amzn.to/34NVmwx

This book is a must read - it will put you in another level! (Expert)
Agile Software Development, Principles, Patterns, and Practiceshttps://amzn.to/30WQSm2

Write cleaner code and stand out!
Clean Code - A Handbook of Agile Software Craftsmanship: https://amzn.to/33RvaSv

This book is very practical, straightforward and to the point! Worth every penny!
Kotlin for Android App Development (Developer's Library): https://amzn.to/33VZ6gp

Needless to say, these are top right?
Apple AirPods Pro: https://amzn.to/2GOICxy

😱👆 PROMOTIONAL DISCOUNT: BOOKS AND IPODS PRO ðŸ˜±ðŸ‘†