Search code examples
androidandroid-activitystartup

Unable to launch a new activity as main activity


Initially my Android project had only one activity named MainActivity. Then, I added a new activity named ChildActivity into my project. I'm trying to launch my new activity as startup activity when app gets launched. I changed AndroidManifest.xml file to achieve it. I moved the entire intent-filter tag from MainActivity to ChildActivity as shown below:

<activity android:name=".MainActivity">

        </activity>

        <activity android:name=".ChildActivity" >

            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

        </activity>

Layout file of ChildActivity looks like this. I'm trying to show a TextView on the new activity I've just added:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".ChildActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_display"
        android:text="Hello this is Rasik!"/>

</android.support.constraint.FrameLayout>

ChildActivity.java file:

package com.example.android.explicitintent;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

public class ChildActivity extends AppCompatActivity {

    private TextView mDisplayText;

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

Whenever I try to debug my app in Android AVD, nothing happens. It seems my app is crashing at start up. Can anyone help me in diagnosing the root cause?


Solution

  • The class android.support.constraint.FrameLayout not exists. Try LinearLayout, FrameLayout, android.support.constraint.ConstraintLayour or others