Android Interview questions list will never end. Android is changing most frequently and updating new components in android app development. Here we are sharing top android interview questions for android developers.
Here are the top Android Interview Questions
1. What is Android Activity Lifecycle?
Answers: Activity Lifecycle is a favorite question all the time. It’s important for Beginner and experienced Android developers to know about the full Lifecycle of activity.
Activity lifecycle has seven methods, which help in maintaining your application. These call methods are very helpful from a developer’s perspective.
onCreate()
onStart()
onResume()
onPause()
onStop()
onRestart()
onDestroy()
This answer will go long so go to this link Android Activity Lifecycle with an example, you will complete example and details.
2. What is the difference between contentP rovider and contentResolver in android?
Answers : Content Resolver resolves a URI to a specific Content providers.
Content Provider provides an interface to query content to other apps or own app can interact.
The way to query a content provider is contentResolverInstance.query(URI,.....)
3. Difference between Parcelable and Serializable?
Answers: Serializable is a standard Java interface. It is not a part of the Android SDK. Just by implementing this interface, your POJO will be ready to jump from one activity to another.
public class UserModel implements Serializable { String name; public UserModel(String name) { this.name = name; } public String getName() { return name; } public void setName(String name) { this.name = name; } }
Parcelable is another interface, it’s a part of the Android SDK. Now, Parcelable was specifically designed in such a way that there is no reflection when using it. That is because we are being really explicit about the serialization process.
public class UserModel implements Parcelable { String name; public UserModel(String name, String id) { this.name = name;} protected UserModel(Parcel in) { this.name = in.readString();} public String getName() { return name;} public void setName(String name) { this.name = name;} @Override public int describeContents() { return 0;} @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.name);} public static final Parcelable.Creator<UserModel> CREATOR = new Parcelable.Creator<UserModel>() { @Override public UserModel createFromParcel(Parcel source) { return new UserModel(source); } @Override public UserModel[] newArray(int size) { return new UserModel[size];} }; }
Its Seems tough ? But in Kotlin Parcelize is more advance not need that much code.
import android.os.Parcelable import kotlinx.android.parcel.Parcelize @Parcelize data class Student (val id:Long, val name: String, val age: Int) : Parcelable { }
That it ! no so much code and hard implementation process in kotlin. You must read Parcelable Android Kotlin (Parcelize).
Conclusion.
- Parcelable is faster than Serializable interface
- A serializable interface is easy to implement, where the Parcelable interface takes more time for implementation.
- Parcelable array can be pass via Intent in android
- The serializable interface creates a lot of temporary objects and causes quite a bit of garbage collection
4. How to Set the entire Android Application in Portrait mode?
Answers: We can set enter android app in portrait mode by Create MyApplication class and extend the Application class.
Here is complete example : Android Application in Portrait mode.
5. How to Communication between two fragments?
Answers: Communication between two fragments can be done with Activity. Two Fragments can send direct messages to each other. Here are 2 ways to achieve it.
First using the interface, create an interface in Sender, and pass the data to the Main Activity. Then From the main activity to pass a data fragment Receiver. Read complete tutorial Communication between two fragments.
The second is using ViewModel, create a ViewModel class, and implements methods in Sender to pass the data to Receiver. Read complete tutorial Share data between fragments used ViewModel.
6. Differences between ConstraintLayout and RelativeLayout
Answers : In the list of 2018 interview questions , this is the top ranking android interview question.
ConstraintLayout has a flat view hierarchy unlike other layouts, so it does a better performance than relative layout. This is the biggest advantage of Constraint Layout. Drag and drop GUI builder feature is second.
Here is a complete tutorial on Differences between ConstraintLayout and RelativeLayout.
7. Deference between Handler vs AsyncTask vs Thread in Android
Answers : Personally I don’t like this question, it seems like a hurdle question.
AsyncTask
and Handler
are written in Java (internally they use a Thread), so everything you can do with Handler or AsyncTask, you can achieve this using a Thread
too.
Its very long to give in details so here is the separate answer for it Handler vs AsyncTask vs Thread.
There is no option to escape with these top 7 questions, it’s the most common and important android interview questions for android developers.