Android screen crack prank

In this post, we are going to develop an application, its kinda game which can be used to prank your friends. :). Yes, you want to fool your friends with a simple android application, just go through the post to develop one for you :). I would like to name this application – ‘Screen crack prank’.

Application’s theme:

Let your friends play the game on your Android phone and see how the screen cracks and the screen goes black and also vibrates. Your friends will believe they broke your phone.

You must have already seen such applications in Google play but creating one such application is really fun!!

Let us start creating the application:

Quick Links

Project Structure

  • Create new android project [File >> New >> Android Project] with project name TapperApp
  • Click next and select target android device version [I chose version 2.2]
  • Click next and enter package name – ‘’
  • Click finish

Code Listings

Layout creation:

We will create a simple layout which has one textview to display instructions and one button who is the hero of ‘Screen Crack Prank’ app. 🙂


Replace the XML present in /res/layout with the below one:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""

        android:text="Challenge for you!"

        android:text="INSTRUCTIONS:nnTry to tap the button 100 times within 30 seconds.nnBest of Luck!"



The application layout should look like:


We have to add few resources before we proceed with writing logic for the application.

Load cracked_screen.png (crack image) under /res/drawable-hdpi folder and glass.ogg (glass breaking sound file) under /res/raw folder. If raw folder is not created, create one under /res folder.

Application logic:


Logic behind the application is given below:

Open TapperAppAcitivty class under package and add the below class. Each line of code is commented to let you understand the code logic.


import java.util.Random;
import com.example.tapperapp.R;
import android.os.Bundle;
import android.os.Vibrator;
import android.content.Context;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class TapperAppActivity extends Activity implements OnClickListener{
	MediaPlayer mPlayer;
    public void onCreate(Bundle savedInstanceState) {
        //Set application layout
        //Assign media player object with sound file
        mPlayer = MediaPlayer.create(TapperAppActivity.this,;
        //Find the button			
        ((Button) findViewById(;

    public void onClick(View v) {
    	//If our applicaitons' button is clicked
		if (v.getId() {
			//Get the button text which is 100
			int i = Integer.parseInt(((Button) v).getText().toString());
			//Decrement button text value and set it as button text
			((Button) v).setText(Integer.toString(--i));
			//Create Random object
			Random gen = new Random();
			//If random value btwn (0 - 9)+1 equals to 10 or i is lesser than 50
			if ((gen.nextInt(10) + 1 == 10) || (i<50)) {
				//Call crack method
				//Make listener to button as null
				((Button) v).setOnClickListener(null);

	private void crack() {
		//Call audio effects method
		//Call visual effects method
		//Call vibrate effects method

	private void audibleFX() {
		//Play sound file

	private void visualFX() {
		//Set background with broken glass image
		//Set title textview with color 0x6400ff00
		//Set blurb textview with color 0x64ffffff
		//Set button  with color 0x64cdc9c9

	private void touchFX() {
		//Create vibrator object
		Vibrator mv = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
		//Vibrate for 500 MS
		mv.vibrate(new long[]{ 0, 500, 0 }, -1);

	protected void onDestroy() {
		// Release mediaplayer
		if (mPlayer != null) {
			mPlayer = null;
Add vibrate permission in Androidmanifest.xml:
<uses-permission android:name="android.permission.VIBRATE" />

To know more about how to use vibration service in Android, see Android vibrate example



Congratulations, We are done.
Let us test the application:
Right click on the project >> Run as >> Android application >> Choose emulator or device
Tap on the button and see what happens.

Download Source Code

Entire project is zipped and is available for download. Unzip the downloaded project and to import the project into eclipse, launch eclipse >> File >> Import.. >> Choose downloaded project(How to import android project in eclipse). If you just want to run the application in your mobile and see the output but don’t want to hit your head with source code, download application(apk) file and install it in your mobile device.

Download Source Code Download Application(apk)

*apk in Android is the installation file simliar to exe in windows.


I hope you enjoyed the post!! 🙂

Suggested posts for further reading


Related Articles

Author: Udhay

Share This Post On
468 ad
  • g.gopikrishna

    how to remove ram memory in android device using java code or phonegap code .please provide slolution for me

  • Wiltshire

    My brother recommended I might like this blog. He was entirely right. This publish truly made my day. You can not imagine just how a lot time I had spent for this information! Thank you!

  • MrCleanX

    Great post! Great Blog! Just what I need to get rolling in Droid programming. Thanks, and keep it up!

  • Samuel

    Hi I’ve followed your instruction and have recreated the app using Eclipse, only changing minor bits such as the “android:text=” part into using a @string method (This was flagged by Eclipse) and the file name of the main.xml

    After finishing that I tried to run it on an emulator as well as my own Android device. While at first it runs, it force quitted after playing the glass sound, without displaying the cracked_glass png as well as any vibration.

    I tried using your source code provided at the end of this guide and it works.

    Any idea what I’ve done wrong?

  • aravind

    nice post

Join now to get more access to our Android Tutorials

Join now to get more access to our Android Tutorials

Once you Join, you will receive Mail containing latest Android Tutorials once a month !!

I promise I wont spam you !!

You have Successfully Subscribed!

Pin It on Pinterest