Posts

Showing posts from December, 2019

CustomView based Android interview questions and answers

1) Design one custom view for displaying TextView in UI with a attributes tribute like Title and Colour. When we need to create any custom view in Android, we will extend our class from the View parent class. In this scenario, as we need to create a custom Text view so we will create a subclass of TextView class.  And then we can our Custom textview in a layout.xml file. For example please follow below code where I am trying to create Custom TextView CustomTextView extends TextView { private String title;     private boolean color; title = tarry.getString(R.styleable.CustomTextView_settitle);             if(title == null)             setText("Custom Message");             else                 setText("Welcome to the Class"); color = tarry.getBoolean(R.styleable. CustomTextView _setColor, false);             if(color == true)             setTextColor(Color.RED); } We need to define our custom textview  in \res\layout  folder and write the code like as shown below. &l

Menu based Android interview questions and answersd

1) Suppose if I want to change menu Item at runtime what approach I should follow? Menu Item is part of the menu.xml file. When we want to add a menu in-out activity we need to method OnCreateOptionMenu(Menu menu). But If you want to add any Menu Item at run time then the system calls your activity’s onPrepareOptionsMenu() method. this method passes currently exist menu object to modify the menu item. Please follow the below code for more detail: @Override public boolean onPrepareOptionsMenu(Menu menu) {     if(Build.VERSION.SDK_INT > 11) {         invalidateOptionsMenu();         menu.findItem(R.id.option1).setVisible(false);         menu.findItem(R.id.option2).setVisible(true);     }     return super.onPrepareOptionsMenu(menu); A

Notification based Android interview questions and answers

1) What is the use of Notification Chanel and how to create it? Notification Channels. Notification Channels allow us to separate notifications into different groups/categories. Basically, Notification Channel is designed for User. They can get full control of what they want to be notified about. If they don’t want any notification they can specifically turn off notifications for a certain channel. They can also specify importance as well as the preferred sound for a particular category of notifications and determine whether or not to override Do not disturb The NotificationChannel constructor requires us to specify the channel_id and channel_name strings. The Importance argument is an int which specifies the level of interruption by the notification. val  MessagesChannel = NotificationChannel(                    MESSAGES_CHANNEL_ID,                    context.getString(R.string_channel_name),                    NotificationManager.IMPORTANCE_DEFAULT) notificationManager.createNotifica

Architecture Components based Android interview questions and answers

Image
What is Android Jetpack and why to use this?  -  Learn from here What are Android Architecture Components?  -  Learn from here ViewModel What is ViewModel? Viewmodel is a Jetpack component, The class is designed to store and Manage the UI related data. To handle data upon Lifecycle changes of activity/application, Like Screen orientation changes.   How to create ViewModel class in Android To work with ViewModel we need to create a class that should be extends from ViewModel class.   How to instantiate ViewModel Class? We can instantiate ViewModel class by two way With default constructor(new key word in java) With ViewModelProvider class Class MyViewModel() extends ViewModel{ }     1=> MyViewModel obj=new MyViewModel()     1=> MyViewModel obj= ViewModelProvider(this).get(MyViewModel.class)      Note:  Always use ViewModelProvider to create ViewModel objects rather than directly instantiating an instance of ViewModel.   Why we need to create ViewModel object with ViewModelProvider

Networking based Android interview questions and answers

Which method to open Http connection to an Uri? A) url. openConnection( ) To get data from Webserver to Android application, which of the following class you need to use to establish connection? A) HttpURLConnection 02 Android JSON Parsing What is JSON? A) JSON is a minimal, readable format for structuring data. It is used primarily to transmit data between a server and web application, as an alternative to XML What is the name of Android class do we need to use to build up an JSON object? A) JSONObject Assume that we have an Android object named stored in reader variable, and inside it has a child object named? A) JSONObject mainObj = reader.getJSONObject("main"); What is JsonParsing? Ans: JSON stands for Javascript object notation, a format for data exchange from the server. In Android, when we work with the online database, we need to convert table data into JSON data, and to manipulate those data Android provides a different way for JSON Parsing. HTTP Url

Sharedpreference based Android interview questions and answers

1) What is Shared Preference and Write its Syntax? Answer: Shared Preference is used to store and retrieve small data like login details in the form of key-value of the pair. To save data in SharedPreference: Editor edit=SharedPreferences(); edit.putString(“key”,”value”); edit.commit(); To retrieve data from shared Preference: SharedPreferences share = new SharedPreference(key,Context.Mode_Private); What is SharedPreferences in Android? Ans:  In android Shared preferences are used to store and retrieve primitive information. In shared preferences, we store information in key and value formats. When we call key automatically value gets printed . The shared preferences concept is wildly used in user settings. In order  to implement the shared preference, there is a method called  getSharedPreferences() getPreferences()

SQLite based Android interview questions and answers

1) What are joins that are not supported by SQLite? Answer: Right outer join and full outer joins 2) What are SQLite and its methods? Answer: SQLite is a relational open source database which comes inbuilt in android devices which enables you to store, retrieve, manipulate and delete data. Using SQLite android application can run in offline mode also. Sqlite is implemented in our project by extending the class with SqliteOpenHelper class which overrides 2 methods i.e; 1.oncreate() -Where the database is created along with its version. 2.onUpgrade() -It is supporting function of onCreate() when the version has updated the changes in a database will be performed in an on upgrade method without disturbing the existing one 3) What is the limit of data storage in sqlite? Answer: Maximum data SQLite can store depends on the storage space of your device. SQLite database save data in which storage? A) Internal storage There are five different methods to store persistent data. They are: Shared

Manage Task based Android interview questions

1) What are "launch modes"? 2) Suppose there are two activities in a single android application with launch modes as 'singleInstance'. Assume an example below.I am navigating from activity A -> B(launchMode="singleInstance"). Now from activity B -> C. Finally, I navigate from activity C -> D(launchMode="singleInstance").Now we know the instance of activity B will be created in a different task, and A & C will be in different tasks.Now, my question is, in which task instance of activity D would be placed. Will it be with activity B, or some other task would be created for activity D? Launch mode is an instruction for Android OS which specifies how the activity should be launched. It instructs how any new activity should be associated with the current task. So in your scenario When using launchMode="singleInstance", there are two things that we need to remember: The Activity will always be created in a new task All Activities l

Memory optimization based Android interview questions and answers

Memory Leaks 1) How do you find memory leaks in the mobile app on the Android platform? Answer:  Android Studio is using Android Device Manager (ADM), this ADM is used to detect the memory leaks in the Android platform. When you open ADM in the Android Studio then on the left-hand side of the ADM, you will find your device or emulator in which a heap sign will be displayed. When you are running any mobile app then you will see the heap size, memory analysis and other statistics displayed on it. CAN YOU PROVIDE SOME IDEAS ON HOW TO PREVENT MEMORY LEAKS INU YOUR APP? There are many strategies that can be applied. Here there is just a small set of ideas. -Is better to use an Application Context rather than an Activity Context , since Activities are more likely to be leaked. -Is generally good to avoid having long-lived references to Activities. -Is better to avoid non-static inner classes in Activities unless we control their lifecycle. Is better to use static inner classes with weak refe

Dialog based Android interview questions and answers

1) Which are the dialog boxes supported by the Android platform? Answer:   Android supports six types of dialog boxes: AlertDialog : It has a maximum of 3 buttons and sometimes AlertDialog includes checkboxes and Radio buttons to select the element. ProgressDialog : It displays the progress bar or wheels. TimePickerDialog : Using this dialog box, a user selects the Time. DatePickerDialog : Using this dialog box, a user selects the Date BottomSheetDialog Finger print Dialog

Design Patterns based Android interview questions and answers

Image
1.Creational Design Pattern Factory Pattern Abstract Factory Pattern Singleton Pattern Prototype Pattern Builder Pattern. What is singleton pattern? Singleton is a most commonly used design pattern and is used when we want one and only one instance of a class per JVM. Classes developed to perform business logic is good example of Singleton class. Name one singleton class in Java? Runtime How we can create a class singleton? To make any class singleton, we need to consider or implement following- Private or protected constructor- We need to make the constructor of a class private so that no one from outer world can call a “new”. Create a private static instance of the class. Create a public static method which will return the instance created. Explain early and lazy loading of singleton class? We can have an early and lazy loading of a singleton class. In case of early loading, an object of singleton class is instantiated while loading of  a class where as in case of lazy loading object

RecycleeView based Android interview questions and answers

1) How does RecyclerView work? RecyclerView is designed to display long lists (or grids) of items. Say we want to display 100 row of items. A simple approach would be to just create 100 views, one for each row and lay all of them out. But that would be wasteful because at any point of time, only 10 or so items could fit on screen and the remaining items would be off screen. So RecyclerView instead creates only the 10 or so views that are on screen. This way you get 10x better speed and memory usage. But what happens when you start scrolling and need to start showing next views?  Again a simple approach would be to create a new view for each new row that you need to show. But this way by the time you reach the end of the list you will have created 100 views and your memory usage would be the same as in the first approach. And creating views takes time, so your scrolling most probably wouldn’t be smooth.  This is why RecyclerView takes advantage of the fact that as you scroll, new rows c

Loaders interview questions and answers

 What are Loaders in Android? Loader API was introduced in API level 11 and is used to load data from a data source to display in an activity or fragment. Loaders persist and cache results across configuration changes to prevent duplicate queries. Checkout the  Sample Implementation .

Toast based Android interview questions and answers

 What is Toast in Android? Android Toast can be used to display information for the short period of time. A toast contains message to be displayed quickly and disappears after sometime. 2) When using setDuration() for a Toast, is it possible to set a custom length or at least something longer than Toast.LENGTH_LONG? A toast can be displayed on the screen is defined by a flag as Duration. We can set duration Short or Long. The value for Short is 2.0 second and value for Long is 3.5 Second. Context context = getApplicationContext(); Toast.makeText(context, "Testing Toast Message.", Toast.LENGTH_SHORT).show(); You can not directly change the duration of Toast Message which is showing in the show() method. But there is a workaround. You can use CountDownTimer Class or Handler Class to increase display time of Toast. Schedule a countdown until a time in the future, with regular notifications on intervals along the way. you need to create a new Window manager and show and hide the