无法将MyApplication分配给活动 [英] MyApplication not assignable to Activity

查看:155
本文介绍了无法将MyApplication分配给活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试进行全局变量活动.

I am currently attempting to make a global variable activity.

我已遵循以下说明( Android全局变量)来设置活动".

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

但是,当我尝试编辑 android:name 属性时,就会出现问题.当我输入应用程序/活动的名称时,错误消息显示我无法扩展应用程序.有人可以解释为什么吗?

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?

清单:

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

和Protoype2活动:

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

}

推荐答案

Application和Activity是两个单独的类.如果要扩展Application类,则不要在清单中也声明与Activity相同的类-

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 -

从清单中删除此代码-

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

这篇关于无法将MyApplication分配给活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆