How to start or open new activity or window from one window on button click

Requirement: You want to make an "app", which displays a login screen, and users can log in. If the login is correct,  open a new window, where users can do other staff. Then how can you do this?


Step 1. Create a layout xml for the new window. In my case I have created one
named newwindow.xml . The entry are as follows --

<?xml version="1.0" encoding="utf-8"?>
<Gallery xmlns:android=""
    android:background="#9999FF" >

Step 2. Create a class with extending Activity .

Step 3. On that new class add --

public void onCreate(Bundle savedInstanceState) {

Here newwindow is the layout xml.

Start Up window is given bellow --

Step 4. Add the new class on AndroidManifest.xml

Note that, if you don't add the class on AndroidManifest.xml app will crash ("the app stopped unexpectedly").

Step 5. Now add the following where you want to initiate this new activity or window ---

Intent intent = new Intent(getApplicationContext(), NewWindow.class);
 That's all!

Now If you add it on button click then the output will be --

You can see that the new windows background colour is "#9999FF" .

Post a Comment