To develop a Android Application that creates an alert upon receiving a message.


Creating a New project:

  • Open Android Studio and then click on File -> New -> New project.

new project

  • Then type the Application name as “″ and click Next. 


  • Then select the Minimum SDK as shown below and click Next.

minimum sdk

  • Then select the Empty Activity and click Next. 

empty activity

  • Finally click Finish.


  • It will take some time to build and load the project.
  • After completion it will look as given below.


Creating Second Activity for the Android Application:

  • Click on File -> New -> Activity -> Empty Activity.

New activity

  • Type the Activity Name as SecondActivity and click Finish button.


  • Thus Second Activity For the application is created.

Designing layout for the Android Application:

  • Click on app -> res -> layout -> activity_main.xml.


  • Now click on Text as shown below.


  • Then delete the code which is there and type the code as given below.

Code for Activity_main.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_margin="10dp" android:orientation="vertical"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Message" android:textSize="30sp" /> <EditText android:id="@+id/editText" android:layout_width="match_parent" android:layout_height="wrap_content" android:singleLine="true" android:textSize="30sp" /> <Button android:id="@+id/button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margin="30dp" android:layout_gravity="center" android:text="Notify" android:textSize="30sp"/> </LinearLayout>
  • Now click on Design and your application will look as given below.


  • So now the designing part is completed.

Java Coding for the Android Application:

  • Click on app -> java -> com.example.exno10 -> MainActivity.


  • Then delete the code which is there and type the code as given below.

Code for

package com.example.exno10; import;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText; public class MainActivity extends AppCompatActivity { Button notify; EditText e; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); notify= (Button) findViewById(; e= (EditText) findViewById(; notify.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(MainActivity.this, SecondActivity.class); PendingIntent pending = PendingIntent.getActivity(MainActivity.this, 0, intent, 0); Notification noti = new Notification.Builder(MainActivity.this).setContentTitle("New Message").setContentText(e.getText().toString()).setSmallIcon(R.mipmap.ic_launcher).setContentIntent(pending).build(); NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); noti.flags |= Notification.FLAG_AUTO_CANCEL; manager.notify(0, noti); } }); }
  • So now the Coding part is also completed.
  • Now run the application to see the output.


android application  Screenshot_2016-03-16-00-41-32

Screenshot_2016-03-16-00-41-44  Screenshot_2016-03-16-00-41-53


              Thus Android Application that creates an alert upon receiving a message is developed and executed successfully.

Similar Posts