Quiz App in Android studio source code free – Android Tutorial

Quiz App is an android based application, and enables the user to undertake a series of questions on Java language. The app is user friendly, and the user shall find it extremely easy to answer the multiple-choice questions. At the end of the quiz, a result-report is generated which states the score. The Quiz app also presents an option to the current user to play the question-round again or quit in between.

This Quiz App was developed as a learning project for Android. It is developed in Android Studio 3.6

  • compileSdkVersion – 29
  • buildToolVersion – 28-0-3
  • minSdkVersion – 17
  • targetSdkVersion -29

Again that we are well versed with Activity, Layout, Views etc its time to get our hands dirty, and create our second application. This application will have a science quiz app, and user will have option to answer in True or False. Based on what the user enters, we will show the user, whether they selected the correct option or not by simply showing a message saying Correct or Incorrect.

<img src="quiz.png" alt="quiz app thumbnail">

For Quiz App Open Android Studio and go to File → New → New Project. In the New Project window, enter the Application Name as Quiz and company domain as com.technic.quiz and Click on Next.

MainActivity

package com.technic.javaquizapp;

import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;



public class MainActivity extends AppCompatActivity {
    Button playGame,quit,share;
    TextView textView;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home_screen);
        setTitle("");

        //the below method will initialize views
        initViews();

        //PlayGame button - it will take you to the MainGameActivity
        playGame.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(MainActivity.this, GameActivity.class);
                startActivity(intent);
                finish();
            }
        });


        //Quit button - This will quit the game
        share.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Intent sharingIntent = new Intent(Intent.ACTION_SEND);
                sharingIntent.setType("text/plain");
                sharingIntent.putExtra(Intent.EXTRA_TEXT, "Try this new ** App   ");
                sharingIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
                startActivity(Intent.createChooser(sharingIntent, "Share using"));

            }
        });


        //Quit button - This will quit the game
        quit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this)
                        .setIcon(R.drawable.alrt)

                        .setTitle("Are you sure to Exit")
                        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                //set what would happen when positive button is clicked
                                finish();
                            }
                        })

                        .setNegativeButton("No", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                //set what should happen when negative button is clicked
                                Toast.makeText(getApplicationContext(), "Welcome Back", Toast.LENGTH_LONG).show();
                            }
                        })
                        .show();
            }
        });
    }

    private void initViews() {
        //initialize views here
        playGame =(Button)findViewById(R.id.playGame);
        quit = (Button) findViewById(R.id.exit);
        textView = (TextView)findViewById(R.id.tQ);
        share = (Button)findViewById(R.id.share);


        //Typeface - this is for fonts style
        Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/main-Bold.otf");
        playGame.setTypeface(typeface);
        quit.setTypeface(typeface);
        textView.setTypeface(typeface);




    }
}

In the next step you will be asked to select the targeted device, on which your application will be supported. Let’s stick with Phone and Tablet for this Quiz App application. And in the drop down saying Minimum SDK choose API 16: Android 4.1 (Jelly Bean), this means our App will work on all the Phones and Tablets with Android Version 4.1 till 7(the latest version). Click on Next button.

Layout File of Quiz

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fbutton="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity="center_horizontal"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/tQ"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/app_name"
        android:textColor="#2b2b2b"
        android:textSize="50sp"
        android:textStyle="bold"
        android:background="@drawable/quiz_bg"
        android:layout_marginTop="10dp"
        android:padding="5dp"

        />

    <View
    android:layout_width="match_parent"
    android:layout_height="20dp"
        android:layout_marginTop="50dp"
        />

<ImageView
    android:layout_marginTop="-50dp"
    android:layout_width="250dp"
    android:layout_height="250dp"
    android:src="@drawable/logo"
    android:layout_marginBottom="10dp"
    />




    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"

        >

        <Button
            android:layout_marginBottom="10dp"
            android:id="@+id/playGame"
            android:background="@drawable/button_bg"
            android:layout_width="300dp"
            android:text="Play Game"
            android:layout_height="wrap_content"
            android:textColor="@color/white"
            />


    <Button
        android:layout_marginBottom="10dp"
        android:textColor="@color/white"
        android:id="@+id/share"
        android:background="@drawable/button_bg"
        android:layout_width="300dp"
        android:text="SHARE"
        android:layout_height="wrap_content" />


    <Button
        android:layout_marginBottom="10dp"
        android:textColor="@color/white"
        android:id="@+id/exit"
        android:background="@drawable/button_bg"
        android:layout_width="300dp"
        android:text="QUIT"
        android:layout_height="wrap_content" />



    </LinearLayout>



</LinearLayout>

Now its time to add the first Activity to our application. Select the Empty Activity from the avilable options. And click on Next.

Enter the activity name to be MainActivity, and Android Studio will automatically fill the layout file name. It is a standard practice to add suffix Activity in the Activity names and we will follow it. And for layout XML file, it is all words in small and in reverse order, separated by underscore _. Click on Finish to create the Quiz app project.

Manifest File for Quiz

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.technic.javaquizapp">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity"
            >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity android:name=".GameOverActivity" />
        <activity android:name=".WonActivity" />
        <activity android:name=".TimeOverActivity" />
        <activity android:name=".GameActivity">

        </activity>
    </application>

</manifest>

Android Studio will take some time, to build everything, so be a little patient. Once Android Studio finished building your project, you will see a new project added to the left project tool window, the activity file will be open and in the Preview tool window you will see the preview for your app. Quiz App-If the Preview tool window in not open, go to View → Tool Windows → Preview, and the preview window will show up on the right side. Make other Java Quiz App Click Here.

YouTube Video

There are four Activities in the app :

Main – displays Home Screen of application.
Questions – displays MCQ’s and currents Score.
Results – displays Results after finishing the quiz.
Developers – displays the information about the developers.

Quiz app Download Source Code

Click below to get the source code android Quiz application.

Download Quiz Apk: Click Here
Quiz Logo Download: Click Here

Download Source Code

Click below to get the full source code android Quiz App application.

Conclusion

We have successfully created a Quiz App Android application using Android Studio.


Cheers!

READ MORE…

DeepCrazyWorld

Hey, I'm Deepika a professional blogger and Experienced in Android Developer,Flutter Developer, PHP Web Developer. Technically sound Post graduate pursuing M.Tech in Computer Science and Engineering. I Love to gain every type of knowledge that's why i have done many courses in different fields like engineering and technology. Skilled in Java, HTML, CSS,Bootstrap,j query PHP, Python, SQL, C, C++,Firebase,MySQL,SQLite,JavaScript. Also I have learned Networking.

Leave a Reply