Saturday 18 March 2017

Android interview questions

Activity :-



Save your activity state : 

As your activity begins to stop, the system calls the onSaveInstanceState() method so your activity can save state information with a collection of key-value pairs.

Restore your activity state : 

Instead of restoring the state during onCreate() you may choose to implement onRestoreInstanceState(), which the system calls after the onStart() method. The system calls onRestoreInstanceState() only if there is a saved state to restore, so you do not need to check whether the Bundle is null

Handling multi-window cases : Multi-window mode does not change the activity lifecycle
. In multi-window mode, an app can be in the paused state and still be visible to the user.
When the user puts an app into multi-window mode, the system notifies the activity of a configuration change,

Configuring Your App for Multi-Window Mode : 


android:resizeableActivity=["true" | "false"]

Disabled features in multi-window mode


Some System UI customization options are disabled; for example, apps cannot hide the status bar if they are not running in full-screen mode.
The system ignores changes to the android:screenOrientation attribute.

picture-in-picture mode : android:supportsPictureInPicture=["true" | "false"]

its mainly used for Android TV and video play backs

Declaring Your Activity Supports Picture-in-picture :  


your video activity in your manifest by setting android:supportsPictureInPicture and android:resizeableActivity to true. And layout configuration changes

Switching Your Activity to Picture-in-picture : getActivity().enterPictureInPictureMode();

freeform mode :


Manufacturers of larger devices can choose to enable freeform mode, in which the user can freely resize each activity. If the manufacturer enables this feature, the device offers freeform mode in addition to split-screen mode.


Android 7.0 for Developers

  1. Multi-window Support 
  2. Notification Enhancements 
    1. Template updates : hero image and avatar
    2. Messaging style customisation : You can configure the message, conversation title, and content view.
    3. Bundled notifications : A user can take actions, such as Dismiss or Archive, on them in place. If you’ve implemented notifications for Android Wear, you’ll already be familiar with this model.
    4. Direct reply
    5. Custom views
  3. Quick path to app install : ART's JIT(Just in time) now install in just a matter of seconds.
  4.  Doze on the go : This means users can save battery even when carrying their devices in their pockets.
  5. Project Svelte : background optimizations : Project Svelte is focused on optimizing the way apps run in the background.
  6. Surface view : The SurfaceView class enables more battery-efficient compositing on screen, because it is composited in dedicated hardware, separately from app window content. As a result, it makes fewer intermediate copies than TextureView.
  7.  Data saver : 
  8. Vulkan API Vulkan is an open standard for 3D graphics and rendering maintained by the Khronos Group.
  9. Quick setting's title API : For developers, Android 7.0 also adds a new API that lets you define your own Quick Settings tiles to give users easy access to key controls and actions in your app.
  10. Number Blocking
  11. new Emojies
  12. ICU 4j libraries :Android framework can produce substantial savings in APK size.
  13. Webview : Chrome +webview together 
  14. Android TV recording : ability to record by selected channels 
  15. Android for work
    1. work profile security
    2. always VPN on 
    3. turn off work
  16. screen Zoom : configuration changes will get changed

Fragments


Passing values between activity and fragement : 

1. get a value from activity : In your fragment you can call getActivity(). This will give you access to the activity that created the fragment. From there you can obviously call any sort of accessor methods that are in the activity.


2. Interface : implementing interface in both acitivty and fragemnt we can update the value 

3 Bundle : savedInstanceState will help to get the data from activity to fragment viva


Fragment to Fragment : 

All Fragment-to-Fragment communication is done through the associated Activity. Two Fragments should never communicate directly.


https://inthecheesefactory.com/blog/fragment-state-saving-best-practices/en



Content Provider

A content provider component supplies data from one application to others on request. Such requests are handled by the methods of the ContentResolver class. A content provider can use different ways to store its data and the data can be stored in a database, in files, or even over a network.




Services

Service is an application component that can perform long-running operations in the background,
JAVA

1. Method overriding : If subclass has the same method as declared in the parent class, it is known as method overriding.








  • Method overriding is used to provide specific implementation of a method that is already provided by its super class.
  • Rules for Java Method Overriding


    1. method must have same name as in the parent class
    2. method must have same parameter as in the parent class.
    3. must be IS-A relationship (inheritance)
                                     
    1. class Vehicle{  
    2. void run(){System.out.println("Vehicle is running");}  
    3. }  
    4. class Bike2 extends Vehicle{  
    5. void run(){System.out.println("Bike is running safely");}  
    6.   
    7. public static void main(String args[]){  
    8. Bike2 obj = new Bike2();  
    9. obj.run();  
    10. }  
         

    Can we override static method?

    No, static method cannot be overridden. It can be proved by runtime polymorphism, so we will learn it later.

    Why we cannot override static method?

    because static method is bound with class whereas instance method is bound with object. Static belongs to class area and instance belongs to heap area.

    Can we override java main method?

    No, because main is a static method.



    Understanding all java access modifiers

    Let's understand the access modifiers by a simple table.
    Access
    Modifier
    within classwithin
    package
    outside
     package
    by subclass
    only
    outside
    package
    PrivateYNNN
    DefaultYYNN
    ProtectedYYYN
    PublicYYYY


    Java access modifiers with method overriding

    If you are overriding any method, overridden method (i.e. declared in subclass) must not be more restrictive.

    Method Overloading in Java

    If a class has multiple methods having same name but different in parameters, it is known as Method Overloading.

    Different ways to overload the method

    There are two ways to overload the method in java
    1. By changing number of arguments
    2. By changing the data type
    1. class Adder{  
    2. static int add(int a,int b){return a+b;}  
    3. static int add(int a,int b,int c){return a+b+c;}  
    4. }  
    5. class TestOverloading1{  
    6. public static void main(String[] args){  
    7. System.out.println(Adder.add(11,11));  
    8. System.out.println(Adder.add(11,11,11));  
    9. }}