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?
The available Abstract classes are listed below: AndroidActivity. IOSActivity.
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.
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 .
Abstraction in the Java programming language involves the creation of one or more interfaces or abstract classes to hide implementation details.
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)."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With