Thursday, July 19, 2018

Starting With Android Studio Part-III || Multiple Activity

Hello friends Welcome again to TechPunch.
In this tutorial we will create app to switch between multiple activity.
Hope you have referred my previous blog for starting with android studio part-II.
Lets Start!!!
  • Start new project.
  • On left hand side there will tree of app just right click on app select new-> Activity->Empty Activity.
  • Give any name to new Activity, in my case its Main2Activity.
  • Drag and drop button in MainActivity to switch from MainActivity to Main2Activity.
  • Go to MainActivity.java and create method and write
  • code for click event of buuton as shown below.
  • code:
public void onClick(View v)

{

startActivity(new Intent(this,Main2Activity.class));

}
  • what above code indicates is public void onClick is a method used to handle click event of MainActivity event.
  • start Activity is method which take Intent as a parameter.
  • Intent contains two parameters one is context of current activity and another is class file Activity that is in which activity you want to switch.
  • After that go to xml code of main acitivity and code for linking button to onClick method.
  • Now you are done to play with it….

No comments:

Post a Comment