Code File (. java file)

MainActivity.java

 

package com.dce.practical1;

 

import java.util.RandomAccess;

 

import android.os.Bundle;

import android.app.Activity;

import android.content.ContentProvider;

import android.content.Intent;

import android.view.Menu;

import android.view.View;

import android.widget.EditText;

import android.widget.Toast;

 

public class MainActivity extends Activity {

 

       EditText edt;

       EditText edt1;

       @Override

       protected void onCreate(Bundle savedInstanceState) {

              super.onCreate(savedInstanceState);

              setContentView(R.layout.activity_main);

       }

 

       @Override

       public boolean onCreateOptionsMenu(Menu menu) {

              // Inflate the menu; this adds items to the action bar if it is present.

              getMenuInflater().inflate(R.menu.main, menu);

              return true;

       }

       public void btn_click(View v) {

              edt=(EditText)findViewById(R.id.editText1);

              edt1=(EditText)findViewById(R.id.editText2);

              //Toast.makeText(this,edt.getText().toString(),Toast.LENGTH_LONG).show();

              String uname=edt.getText().toString();

              String pass=edt1.getText().toString();

              if(uname.equals("admin") && pass.equals("admin"))

              {

             

              Toast.makeText(this,"Login Successfully",Toast.LENGTH_LONG).show();

              Intent a=new Intent(this,HomeActivity.class);

              a.putExtra("uname",uname);

              startActivity(a);

              }

              else

              {

                     Toast.makeText(this,"Enter Valid username and password",Toast.LENGTH_LONG).show();

              }

       }

 

}

 

HomeActivity.java

 

package com.dce.practical1;

 

import java.util.RandomAccess;

 

import android.os.Bundle;

import android.app.Activity;

import android.view.Menu;

import android.view.View;

import android.widget.EditText;

import android.widget.TextView;

import android.widget.Toast;

 

public class HomeActivity extends Activity {

 

TextView txt;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_home);

txt=(TextView)findViewById(R.id.textView1);

Bundle bundle = getIntent().getExtras();

String message = bundle.getString("uname");

txt.setText("Welcome " + message + "!!");

}

 

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.main, menu);

return true;

}

 

 

}

 

Design File (.xml file)

activity_main.xml

 

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent" >

 

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:text="Hello World!"

android:textAppearance="?android:attr/textAppearanceLarge"

android:textColor="@color/Red" />

 

</RelativeLayout>

 

Activity_home.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:layout_width="match_parent"

android:layout_height="match_parent" >

 

<TextView

android:id="@+id/textView1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_centerHorizontal="true"

android:layout_centerVertical="true"

android:text="welcome admin!!!!!!!!!"

android:textAppearance="?android:attr/textAppearanceLarge"

android:textColor="@color/Red" />

 

</RelativeLayout>

 

String.xml

<?xml version="1.0" encoding="utf-8"?>

<resources>

 

<string name="app_name">Practical1</string>

<string name="action_settings">Settings</string>

<string name="hello_world">Hello world!</string>

<color name="Red">#FF0000</color>

<color name="White">#FFFFFF</color>

<string name="Username">Name :</string>

<string name="Login">Login</string>

 

</resources>

 

AndroidMainfest.xml

 

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.dce.practical1"

android:versionCode="1"

android:versionName="1.0" >

 

<uses-sdk

android:minSdkVersion="8"

android:targetSdkVersion="17" />

 

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<activity

android:name="com.dce.practical1.MainActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.MAIN" />

 

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity

android:name="com.dce.practical1.HomeActivity"

android:label="@string/app_name" >

<intent-filter>

<action android:name="android.intent.action.PICK" />

 

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

</application>

 

</manifest>

 

Output

media1 media2