2016-03-19 12 views
0

現在、グローバル変数アクティビティを作成しようとしています。MyApplicationがアクティビティに割り当てられない

アクティビティを設定するには、以下の手順(Android global variable)に従っています。

ただし、問題は、android:nameという属性を編集しようとしたときに発生します。アプリケーション/アクティビティの名前を入力すると、アプリケーションを拡張できないというエラーメッセージが表示されます。なぜ誰かが説明できますか?

マニフェスト:

<?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活性:

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

} 

答えて

1

アプリケーションとアクティビティは2つの別々のクラスです。あなたはApplicationクラスを拡張している場合は、マニフェストでも活動と同じクラスを宣言していない -

は、マニフェストからこのコードを削除 -

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

xmlはダミーであり、よりアプリレイアウトやマニフェストのいずれかのための情報保持/スケルトンのような、彼らロジックやintanceオブジェクトを使うことはできません。またgetter/setterを使うこともできません。

1

を「Protoype2は、」Applicationクラスです。また、Applicationクラスをアクティビティとして宣言することはできません。アクティビティクラスが必要です。

あなたが投稿したリンクは、アクティビティからApplicationクラスにアクセスするためのかなり前の段階です。

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

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

</application> 
で交換してください
関連する問題