6 Android Interview Questions - Interfaces, Fragments, Bitmaps

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello and welcome to another episode in the last video there was a bonus question about async tasks how many threads are in an async task and most of you were right there's two threads that run in an async task on pre-execute runs on the ui thread it runs something before you execute the async task the actual execution due in background runs on the worker thread which is the background thread and then post execute goes back to the main thread the ui thread so two good job you get the pleasure of knowing you were right all right for this video there's some more questions question number one which of the following is a reserved keyword that when used can refer to the functionality of another class so a reserved keyword is a word that you cannot use in your code to refer to anything but the original intent of the word it's reserved by the language i probably wouldn't guess this because i had to try it i don't have the memorized and i never asked myself this question the choices are package extend import and protected the answer is actually not import because you can instantiate variables of these names but you cannot use the word package package is the right answer interesting question question number two how do you communicate between two fragments i usually define an interface and that's what the answer is you define an interface you define it in fragment a you implement it in fragment b the call goes out from fragment a b is notified etc now another answer here is a shared view model and this answer is defined even in the android documentation about this question but i don't think they're looking for the shared view model answer because what if you're not using mdvm what if there are no viewmodels android docs are assuming that you're using nvdm the normal solution would be and the typical very simple solution would be just to implement an interface between them and that's how you get them to communicate this is a nice one in kotlin what is the difference between const and val so both of them are used to define values that do not change or cannot change but the difference is that const is used to initialize this value that does not change at compile time at compile time before running the code you have to know the value of this field with val you can just say val age is equal to five or val h and then you have an if statement and you assign the age inside that so it needs to run to be able to initialize that variable const needs to be known while you compiled it cannot be up to some if or something so that's the difference between them const is for compile time initialization val is for runtime initialization does scotland only work for the jvm no it works for javascript native jvm there's massive effort on kotlin multi-platform going on right now answer is no why would you declare a class as abstract why would you when it doesn't make much sense to have an instance of that class you don't want it to be used in an object you just want it to be a place where you've defined some basic structure and you have some supported behavior which you want the other classes to take over from your class but you don't want anybody to say new my class dot anything it doesn't make sense it works it will compile but there is no use for it so you just make it abstract this one's cool this one's tough in android bitmaps take up large amounts of memory that's true what is the correct way to deal with this issue well as per the android documentation you should read the dimensions of the bitmap before you decode it and they provide that with the in just decode bounds property that property if you set it to true and then you attempt to decode the bitmap this will result in returning null for the bitmap object but at the same time you're gonna get the width the height and the mime type of that bitmap so you could act accordingly when you know them this allows you to read it before you attempt to decode it and run into a crash or an out of memory error here's how the code looks like it's just the property that you apply on the options bitmap factory you get the height width and mime type and i'm supposing here you read it i mean you decode it according to those measurements you resize this technique allows you to read the dimensions and type of the image prior to construction and memory allocation of the bitmap it's pretty interesting question i had no idea next bonus question which of the following is the best way to update a screen periodically choices are alarm manager background service notification manager thread and handler if you know the answer to this question good for you put it in the comments if you don't stick around to the next episode you'll find out thank you for watching i'll see you in the next one
Info
Channel: Oday
Views: 7,568
Rating: undefined out of 5
Keywords: android, android interview questions, memory leak, threads, android service, android interview, programming interview questions, android development, android development tutorial, android pending intent
Id: 5P67zA7AQto
Channel Id: undefined
Length: 5min 35sec (335 seconds)
Published: Sat Feb 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.