Android Development – Changing from one activity to activity

Hello all fellow programmers. Today I have another topic about the fun and exciting android development world. We’ll it’s sort of a beginner kind of topic, but I want to help you guys become experts in Android development so I think it can be justified. ­čÖé Anyways, when I started programming for android I was having trouble with concept of an activity; it seems pretty straightforward, but I think that it can get confusing when you’re starting to develop your first Android application.

Android Activity

An android activity is a java class which is the back-end functionality to a user interface. It’s a very simple concept right? Well then another question came into my head, how do navigate through multiple activities. Well, my friends I will give a short example on how to navigate between activities in this post.

Example:

First Activity

 

 

 

Second Activity:

 

 

So, as you can see in the first activity we have a button named nextActivityButton┬á which is pressed in order to go to the next activity. We set a OnclickListener on the nextActivityButton,┬á so once it is clicked then the code inside the onClick() function is fired, and that’s where all of the cool magic of changing between activities happens. We create an intent, in this case I named it intent. The Intent object takes two parameters. The first parameter is the instance of the current class and the second parameter is the name of the class in which it will go into next. In this case, the second activity is called secondActivity; oh ya don’t forget to put the .class part in the end. Whala, now we are in the second activity. Simple enough, right! and the activities should look something like this:

First Activity User Interface:

 

Second Activity User Interface:

Thanks for making it to the end. Have fun tweaking this example in order to use it for your own projects! Keep coding my friends.

Leave a comment