Java Concepts
A thread pool reuses previously created threads to execute current tasks and offers a solution to the problem of thread cycle overhead and resource thrashing. It is a software design pattern for achieving concurrency of execution in a computer program. Since the thread is already existing when the request arrives, the delay introduced by thread creation is eliminated, making the application more responsive. The size of a thread pool is the number of threads kept in reserve for executing tasks
Can abstract class have static methods?
If we declare a method in a class abstract to use it, we must override this method in the subclass. But, overriding is not possible with static methods. Therefore, an abstract method cannot be static.
We cannot override final class/methods in Java.
But, in-case of abstract, we must override an abstract method to use it.
Therefore, we cannot use abstract and final together before a method.
Android Launch Modes
Standard
This is the default launch mode. If you don’t specify any launch mode, activity will open with standard launch mode.
This is the simplest of all. It’ll just launch one activity over the other. Even if the activity is already present.
For example:
SingleTop
Remember this as: Only a single instance of the activity will remain on top.
In this android launch mode:
- If the Activity is present on the top, then a new instance is NOT created. Instead the onNewIntent() method is invoked.
- If the activity is NOT present on the top, then a new instance is created and added to the top. Just like the standard launch mode.
SingleTask
Remember this as: Only a single instance of an activity can survive in a Task.
If an activity has SingleTask launch mode, then a new Task is created when the activity is launched the first time. And this activity instance is placed at the root. Now for the two cases:
In this android launch mode:
- If an Activity is present on top, then a new instance is NOT created. Instead the onNewIntent() method is invoked.
- If an instance of the Activity is already present but NOT ON TOP, it pops all the other activities and invokes the onNewIntent() method.
SingleInstance
Remember this as: Single Instance in Single Task
In this android launch mode, just like Single Task a new Task is created and the activity placed at the root. But this new task will only contain that activity instance and nothing else. If a new activity is launched from this, then it’s done in a separate task.
Since only one instance can remain in a task:
- If an instance of the activity exists in a different task, then onNewIntent() method is called for that activity.
- If a new Activity is launched from a singleInstance activity, it’s launched in a separate task.
Comments
Post a Comment