Here, I am gonna explore coding, Debugging, Error fixing, My articles and other technical posts. So stay tuned.

Starting one activity to another in android studio | how to go to another activity in Android studio

No comments

Starting an Activity 




As we know Website is a collection of web-pages linked with each other. And the Android app just a collection of Activities linked with each other.  So we need to provide a link to open new activity.


  • Create two Activities in your Android studio.Let say Activity A and Activity B.
  • In both of the create a button A and Button B .
  • In Activity first Go to Java file of it and initialize the button object of button A. As shown in figure below.


  • Then with the Object of button A call the function setOnclickListener() as shown in code below.

  • As this function takes the argument of onClick function. So in the onclick function make the object of Intent class which is used to start the next activity.

  • In the Image above i created the object i of Intent class and this Intent class have one constructor which take the context and the name of the java file of new activity with extention .Java . After that call the function startActivity() and pass the object of the Intent class. Then your hole code will be look like the image given below.


so use this code to open the new activity.

==============================================

I hope you like the way to my teaching to please don't forget to comment below and share with your friends.  

=============================================








No comments :

Post a Comment