Android Studio emulator white screen upon opening of app Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Android Studio emulator white screen upon opening of app without wasting too much if your time.

The question is published on by Tutorial Guruji team.

Whenever I install and run my app in the Android Studio emulator all I get is a white screen and the tool bar above it even though in the preview it works completely fine. Heres the xml code:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="@drawable/rectanglestemlogo"
    android:orientation="horizontal">

    <Button
        android:id="@+id/Home_Button"
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:onClick="goToStemAcademy"
        android:text="@string/Home_Button"
        android:textAllCaps="false"
        android:textColor="#000000" />

    <Button
        android:id="@+id/StemAcademy_Button"
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:layout_marginEnd="0dp"
        android:text="@string/Stem_Academy"
        android:textAllCaps="false"
        android:textColor="#000000"
        android:visibility="visible" />

    <Button
        android:id="@+id/Competitions_Button"
        android:layout_width="0dp"
        android:layout_weight="0.33"
        android:layout_height="wrap_content"
        android:layout_marginEnd="2dp"
        android:text="@string/Competitions"
        android:textAllCaps="false"
        android:textColor="#000000" />

</LinearLayout>

then the java:

package com.example.dmssteamapp6;

import android.content.Intent;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {
    public void goToStemAcademy(View v) {
        startActivity(new Intent(MainActivity.this, StemAcademy.class));
    }
}

then the new xml activity:

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

    <Button
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="138dp"
        android:onClick="goToHome"
        android:text="Button" />
</LinearLayout>

and the java that goes with it:

package com.example.dmssteamapp6;

import android.content.Intent;
import android.view.View;

import androidx.appcompat.app.AppCompatActivity;

public class StemAcademy extends AppCompatActivity {
    public void goToHome(View v) {
        startActivity(new Intent(StemAcademy.this, MainActivity.class));
    }
}

also here is the androidmanifest.xml code if applicable:

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

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

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".StemAcademy"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
        </activity>
    </application>
</manifest>

Answer

Just Create onCreate method in every java class

public class StemAcademy extends AppCompatActivity {

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

 public void goToHome(View v) {
        startActivity(new Intent(StemAcademy.this, MainActivity.class));
    }

}

Activity main class

public class MainActivity extends AppCompatActivity {

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

    public void goToStemAcademy(View v) {
        startActivity(new Intent(MainActivity.this, StemAcademy.class));
    }
}
We are here to answer your question about Android Studio emulator white screen upon opening of app - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji