I have my own base abstract class which extends Activity
class.
public abstract class BaseActivity extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(getLayoutResourceId());
}
protected abstract int getLayoutResourceId();
}
public class Activity1 extends BaseActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// do extra stuff
}
@Override
protected int getLayoutResourceId() {
return R.layout.layout_for_activity1;
}
}
My base class BaseActivity
is not registered in the Manifest
file and I do not get any error.
Is this a time bomb (not registering base class in Manifest) or this is the way it should be? Can someone explain why?
You dont need to register BaseActivity class in manifest because its not the one you call in intent to launch.
for example:
Intent i = new Intent(context, Activity1.class);
startActivity(i);
In above code, you need to have Activity1
activity registered in manifest because you are mentioning it in intent, not the BaseActivity
class.
According to the docs, the <activity>
on the manifest:
Declares an activity (an Activity subclass) that implements part of the application's visual user interface. All activities must be represented by elements in the manifest file. Any that are not declared there will not be seen by the system and will never be run.
Think about it like this: If there's an activity (any class that extends Activity
or a class that extends it) that you will navigate to at some point in your application, it needs to be declared in the manifest. Regardless of how you reach that activity. This excludes classes that only extend the Activity
class but you can't reach directly.
Source
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