Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is android.app.Activity not abstract by design?

Why is android.app.Activity not abstract by design if documentation/tutorials say that at least its method onCreate() must be implemented.

From http://developer.android.com/guide/components/activities.html

You must implement this method. The system calls this when creating your activity.

Even if it was not mentioned explicitly, without the implementation there is no point in having android.app.Activity object, or? I understand that parrent needs probably to execute the code in own implementation of onCreate() but surely there can be design when part of parent onCreate() would a a call to an abstract call-back method which needs to be implemented by the developer.

Example of this design:

public abstract class Activity {


    public abstract void implementThis(Object o);

    public void onCreate(Object o){
        //Do stuff
        implementThis(o);
        //Do other stuff or end.
    }

}

Am I missing something here? Why is there non-abstract Activity if developer must and needs to subclass it and provide custom implementation?

like image 762
ps-aux Avatar asked Aug 15 '13 19:08

ps-aux


People also ask

Is activity an abstract class?

The available Abstract classes are listed below: AndroidActivity. IOSActivity.

What is abstract activity android?

Abstract activity is any activity which has been marked as abstract. And like any other abstract java class, it cannot be instantiated and hence it will fail if passed as intent to startActivity() method. Also Android Studio will not allow you to declare such activity in the manifest file.

Is not abstract Cannot be instantiated?

Abstract classes cannot be instantiated, but they can be subclassed. When an abstract class is subclassed, the subclass usually provides implementations for all of the abstract methods in its parent class. However, if it does not, then the subclass must also be declared abstract .

What is abstract in Android java?

Abstraction in the Java programming language involves the creation of one or more interfaces or abstract classes to hide implementation details.


1 Answers

Read here: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/app/Activity.java#Activity.onCreate%28android.os.Bundle%29

"The default implementation of this method performs a restore of any view state that had previously been frozen by onSaveInstanceState(android.os.Bundle)."

like image 180
ThePerson Avatar answered Oct 05 '22 23:10

ThePerson