Doubt about extends Application

Asked

Viewed 422 times

2

Developing for android I can create a class that extends Application. How would I do it in java? There is this or tagging?

  • You want to extend exactly the Application class or just extend, of any class?

3 answers

5

There is no such thing in Java, it’s a Android thing. In Java you can even invent a class Application for its application, but will not be like the android.app.Application Android, that is, there is no class java.lang.Application or java.app.Application for example that serves as template or basis for your customized subclass.

Some frameworks may provide a base class similar to Application from Android for you to extend, but this would be thing of a specific framework, for you to work with the resources of the framework, and not a thing of Java itself.

2

Yes, there is that.

You can create a class like this:

public class ClasseApplication extends Application{


    @Override
    public void onCreate() {
        super.onCreate();

        //Código a ser executado quando o applicativo é inicializado
    }

}

And on your Androidmanifest.xml, you set the path to the class as the tag attribute.

 <application
        android:name="com.pacote.ClasseApplication" >

In java it is a little abstract, because there are several types of apications in java. In jsf for example there is the Applcation class, which works in a very similar way to android

http://docs.oracle.com/javaee/5/api/javax/faces/application/Application.html

It would help if you were more specific about what kind of application you want to know.

  • yes, on android I do this, I wanted to know otherwise, if it would work like android

  • type, in androi to use extend Application I need to use import android.app.Application; and in java? import javax.ws.rs.core.Application;? , what I want is to start the global variables :)

  • As I said in my reply, in Java there is no default class for this, if it exists it is specific to the framework you are using.

  • I can start my global variables in the Application Extension class?

0

First you must create the parent class. for example.

public class funcionario{} //somente um exemplo

after should extend it or is to create a daughter class so we will use a manager who is an employee.

public class gerente extends funcionario{} //exemplo

recalling that in the daughter class only new methods should be created the rest is inherited.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.