Sunday, December 24, 2017

Android studio open new activity on button click in android by existing activity

Android studio Tutorials 3

What is an "activity" in Android Studio?

An activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.

On every android application there Intent used to open new activity Without intent function developer cannot open another activity. Intent function is used like Anchor tags or you can say that Intent is anchor tag of android applications. So here is the complete step by step tutorial for Open new activity on button click in android by existing activity.

Opening another activity through Intent function.

step 1  creat new activity

Right click app folder



Empty Activitty

See the screen shot

Step 2

Creates a new empty activity

Activity name > Another Activity


See  screen shots

Step 3 

Open main activity xml

Add the code in main activity xml text

        android:onClick="Another Activity"               
       android:text="Start Another Activity"/>

Step 4 

Open  main

add the codes

        public void Another Activity(View view) {
        Intent intent=new Intent(MainActivity.this,AnotherActivity.class);

1 Please Share a Your Opinion.