Quiz App in Android studio source code free – Android Studio 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 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
<img width=

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.

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.java

package com.technic.myjavaquiz;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;


public class MainActivity extends AppCompatActivity {


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


        Button startbutton=(Button)findViewById(R.id.button);
        Button aboutbutton=(Button)findViewById(R.id.button2);
        final EditText nametext=(EditText)findViewById(R.id.editName);

        startbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name=nametext.getText().toString();
                Intent intent=new Intent(getApplicationContext(),QuestionsActivity.class);
                intent.putExtra("myname",name);
                startActivity(intent);
            }
        });

        aboutbutton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(getApplicationContext(),DeveloperActivity.class);
                startActivity(intent);
            }
        });
    }
}

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 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

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity">

    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="55dp"
        android:text="Java Quiz"
        android:textColor="#F44336"
        android:textSize="60dp" />

    <Button
        android:id="@+id/button"
        android:layout_width="200dp"
        android:layout_height="52dp"

        android:layout_above="@+id/textView"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="13dp"
        android:layout_marginLeft="13dp"
        android:layout_marginBottom="215dp"
        android:background="#FF5722"
        android:text="Start"
        android:textColor="#ffffff"
        android:textSize="30dp" />

    <EditText
        android:id="@+id/editName"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="210dp"
        android:ems="10"
        android:hint="Enter your name"
        android:inputType="textPersonName"
        android:textColor="#df040b" />

    <Button
        android:id="@+id/button2"
        android:layout_width="200dp"
        android:layout_height="52dp"
        android:layout_alignStart="@+id/button"
        android:layout_alignLeft="@+id/button"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:layout_marginStart="-2dp"
        android:layout_marginLeft="-2dp"
        android:layout_marginBottom="134dp"
        android:background="#01579B"
        android:text="About"
        android:textColor="#ffffff"
        android:textSize="30dp" />



</RelativeLayout>

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 Main Activity, 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 this app project.

Manifest File

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

    <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=".QuestionsActivity">
            <intent-filter>
                <action android:name=".QuestionsActivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".DeveloperActivity">
            <intent-filter>
                <action android:name=".DeveloperActivity" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name=".ResultActivity"></activity>
    </application>

</manifest>

Android Studio will take some time, to build everything, so be a little patient. source code android quiz,Once Android Studio finished building your project, you will see a new project added to the left project tool window, the activity_science.xml 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.

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

Click below to get the source code android application.

Download Quiz APP Play Store: Click Here

Download Full Source Code

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

Conclusion

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


Cheers!

READ MORE…

DeepCrazyWorld

Hey, I'm Deepika a professional blogger, web designer, Android developer and software engineer. I like to gain every type of knowledge that's why i have done many courses in different fields like engineering and technology. I love thrills and travelling to new places and hills.