maz3tt maz3tt - 6 months ago 15
Android Question

Does every class need to be added to manifest?

package com.example.uu.myapplication;

import android.app.Application;
import java.util.Locale;

public class GlobalClass extends Application
{

private Locale _slocale;

public void setLocale(Locale loc) {
_slocale=loc;
}

public Locale getLocale() {
return _slocale;
}

}


Apart from every activity, do plain classes (as above) be needed to be added to AndroidManifest.xml? If so, then how?

Answer

You only have to add those classes, which have a specific purpose, e.g. Activities. In your example, the GlobalClass inherits from Application. An app usually has a single Application Class that is referenced in the manifest file

 <application android:icon="@drawable/icon" android:label="@string/app_name"
android:name="com.example.GlobalClass">    

Is that really what you want to do?

I assume that you simply want to create classes that hold certain functionality. You can create them as plain Java Files and use them within your Activities, Fragments etc., and you can extend from them.

GlobalClass.java

 public class GlobalClass  {
     private Locale _slocale;

     public void setLocale(Locale loc)  {
         _slocale=loc;
     }

     public Locale getLocale() {
         return  _slocale;
     }
 }

SpecialClass.java

public class SpecialClass extends GlobalClass {
    public void doSomething() {
        Locale currentLocale = this.getLocale();
        ...
    }

    ...
}