javaandroidandroid-manifestextending-classes

MyApplication not assignable to Activity


I am currently attempting to make a global variable activity.

I have followed the following instructions (Android global variable) in order to set the Activity up.

However, the problem comes when I attempt to edit the android:name attribute. When I put in the name of the application/activity, the error message says that I cannot extend Application. Can someone explain why?

Manifest:

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

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

<application
    android:name="Protoype2"
    android:allowBackup="true"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".Protoype2"
        android:label="@string/title_activity_global_var"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>
</application>

And Protoype2 activity:

package com.example.denny.protoype2;

import android.app.Application;


public class Protoype2 extends Application {
    private boolean StopTrue;

    public boolean getStopTrue() {
        return StopTrue;
    }

    public void setStopTrue (boolean StopTrue) {
        this.StopTrue = StopTrue;
    }

}

Solution

  • Application and Activity are two separate classes. If you're extending the Application class then don't declare the same class as an Activity also in the manifest -

    Remove this code from manifest -

    <activity
        android:name=".Protoype2"
        android:label="@string/title_activity_global_var"
        android:theme="@style/AppTheme.NoActionBar">
    </activity>