Android interview question for an experienced developer

Android interview question for the developer

Hi Guys, in the previous post we see the interview question for android In this articles also see remaining Android interview question for an experienced developer with the answer, by reading this article you can easily face interview, let’s start from fragment related questions

1. How to open a fragment from the activity

We can add or replace fragment from activity, let’s see one by one

1. Add:

You can add fragment on the container to do this, firstly you need to specify layout resource id like R.id.layout_container so that FragmentTransaction can add fragment on that container.

Add FrameLayout in your MainActivity.xml we will use this as a container to add or replace fragments.

This is how you can add fragment on layout_container

2. Replace:

Replace fragment is the same as remove(fragment) from all currently added fragment and add a new one on same container view id

3. addToBackStack: 

This is used to add this transaction to the back stack, which will be remembered after it committed.


2. How to open a fragment from another fragment

To open fragment from another fragment you have to replace the fragment

How to pass data from one fragment to another fragment?

You can pass a bundle as an argument like below:

In onCreateView you can get value like below:


3. What is ConstraintLayout

Constraint layout gives you adaptable and flexible ways to create a complex layout using views for your apps. it is now default layout in Android studio

Features of Constraint Layout

  • Convert from other types of layouts to Constraint Layout.
  • You can place dynamically position UI elements onscreen in relation to other elements.
  • You can Animate your views.

4. How to use weight in Layout

You have to add android:layout_weight=”1″ to child layout android assign sum of the weight of child layout to parent layout android:weightSum=”6″ as given below:

Note:- make child layout width is 0  android:layout_width=”0dp”

Output:-


Check more question answers in this post

Thank you 🙂

2 Replies to “Android interview question for an experienced developer”

Leave a Reply

Your email address will not be published. Required fields are marked *