Saturday, 26 April 2025

 AsyncTask In Android 



onPreExecute(), invoked on the UI thread before the task is executed.
This step is normally used to setup the task, for instance by showing a progress bar in the user interface.

doInBackground(Params...), invoked on the background thread immediately after onPreExecute() finishes executing.
This step is used to perform background computation that can take a long time.
The parameters of the asynchronous task are passed to this step.
The result of the computation must be returned by this step and will be passed back to the last step.
This step can also use publishProgress(Progress...) to publish one or more units of progress. 
These values are published on the UI thread, in the onProgressUpdate(Progress...) step.

onProgressUpdate(Progress...), invoked on the UI thread after a call to publishProgress(Progress...). 
The timing of the execution is undefined. This method is used to display any form of progress in the user interface while the background computation is still executing. 
For instance, it can be used to animate a progress bar or show logs in a text field.

onPostExecute(Result), invoked on the UI thread after the background computation finishes. 
The result of the background computation is passed to this step as a parameter.

 What is portable wi-fi hotspot?


Portable Wi-Fi Hotspot allows you to share your mobile internet connection to other wireless device. For examples, using your Android-powered phone as a Wi-Fi Hotspot, you can use your laptop to connect to the Internet using that access-point.

 How to store images of an activity into android phone gallery?


MediaStore.Images.Media.insertImage(getContentResolver(),
yourBitmap,yourTitle,yourDescription);

ContentValues values = new ContentValues(); values.put(Images.Media.DATE_TAKEN, System.currentTimeMillis()); values.put(Images.Media.MIME_TYPE, "image/jpeg"); values.put(MediaStore.MediaColumns.DATA, filePath); context.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);

 REST vs SOAP


SOAP stands for Simple Object Access Protocol. REST stands for REpresentational State Transfer.


SOAP is a XML based messaging protocol and REST is not a protocol but an architectural style.

SOAP has a standard specification but there is none for REST.

Whole of the web works based on REST style architecture. Consider a shared resource repository and consumers access the resources.

Even SOAP based web services can be implemented in RESTful style. REST is a concept that does not tie with any protocols.

SOAP is distributed computing style and REST is web style (web is also a distributed computing model).

REST messages should be self-contained and should help consumer in controlling the interaction between provider and consumer(example, links in message to decide the next course of action). But SOAP doesn’t has any such requirements.

REST does not enforces message format as XML or JSON or etc. But SOAP is XML based message protocol.

REST follows stateless model. SOAP has specifications for stateful implementation as well.

SOAP is strongly typed, has strict specification for every part of implementation. But REST gives the concept and less restrictive about the implementation.

Therefore REST based implementation is simple compared to SOAP and consumer understanding.

SOAP uses interfaces and named operations to expose business logic. REST uses (generally) URI and methods like (GET, PUT, POST, DELETE) to expose resources.

SOAP has a set of standard specifications. WS-Security is the specification for security in the implementation. It is a detailed standard providing rules for security in application implementation. Like this we have separate specifications for messaging, transactions, etc. Unlike SOAP, REST does not has dedicated concepts for each of these. REST predominantly relies on HTTPS.

Above all both SOAP and REST depends on design and implementation of the application.

 Pass ArrayList From OneActivity to AnotherActivity 

public class DataWrapper implements Serializable 
     {
       private ArrayList<String> arrayList;
       public DataWrapper(ArrayList<String> data) 
        {
         this.arrayList = data;
        }
       public ArrayList<String> getArrayList() 
       {
        return this.arrayList;
       }
      }
 

    Intent intent = new Intent(SubCat1Activity.this,Full1Activity.class);
    intent.putExtra("data",new DataWrapper(MainData));
    startActivity(intent);

    DataWrapper dw = (DataWrapper) getIntent().getSerializableExtra("data");
    ArrayList<String> list = dw.getArrayList();

Which method is called when the user leaves the activity ?

onPause

 Which built-in database is Android have ?


SQLite

 Which are must required folders in the android application ?


src & res

 What is the default permission for external storage files ?


Public

 What does .apk extension stand for ?


Application Package kit

 What are the different launch configurations for Android ?


  Run and debug

 The basic building element of Android's user interface is called ?


View

 a mandatory attribute for any view inside of a containing layout manager


layout_width

 Android Apps can share data among other apps


Content Provider

 A folder contains all of the source code of the application ?


src

 component that responds to system-wide broadcast announcements ?


Broadcast Receiver

 when background(AsyncTask) task completes ?


onPostExecute()

 When does onCreate() function of ContentProvider will be called ?


onCreate() will be called when the application containing the content provider is loaded into the memory for the first time.

 What is the difference between menus and dialogs, in android ?


Menus are designed using xml, because menus will not change so frequently. You can build menus using code also when ever required. But it is not recommended to completely build menus using code.
Dialogs are built using code because dialog content will frequently change.

 What is the difference between this context and getapplicationcontext ? 


There are two types of contexts available in android to create any component. 
1. this context (or) this pointer 
2. application context When programmer wants to create any component or control,
 then you have to use one of the contexts. 
 eg: TextView t = new TextView(this); Here we are using this pointer (context). 
 eg: static TextView st = new TextView(getApplicationContext()); 
 Here we are using application context, because it is a static variable whose life time will be through out application life time.

 If you use this pointer here, then it will leak memory (memory wastage) of your activity. 



  View.getContext()

  Returns the context the view is currently running in. Usually the currently active Activity.

  Activity.getApplicationContext()

  Returns the context for the entire application (the process all the Activities are running inside of.
  Use this instead of the current Activity context if you need a context  tied to the lifecycle of the entire 
  application, not just the current Activity. 

  ContextWrapper.getBaseContext()

  If you need access to a Context from within another context, 
  you use a ContextWrapper..
  The Context referred to from inside that ContextWrapper is accessed via  getBaseContext().

 Android web browser is based on which source ?


Android web browser is based with free ware under Apache license that is web kit software.

 Where all I can use Android ?


cars, watches, phones, tablets, laptops, robots, washing machines, traffic controllers, head phones, goggles, TVs.

 Android is released under which license ?


Android is freeware, it is under Apache license but only kernel layer is under GPL license.

 What are the permissions required to obtain phone locations ?


android.permission.ACCESS_FINE_LOCATION - use this if you are using GPS features in your programming. 
android.permission.ACCESS_COARSE_LOCATION - use this if you are fetching locations based on career network or by using WiFi.

 In which library GeoCoder class is located  ?


GeoCoding is part of location's package. It is not related with Maps library.

 How to find whether GPS is disabled in the phone ?


if it is disabled onProviderDisabled() will be called with provider name.

 How to get phone location? which is better network provider or GPS provider ?


You can either use your cell tower information or WiFi information to know your phone location.

 What is the package name of HTTPClient ?


org.apache.http.client



 What is the package name of JSONObject, JSONArray ?


org.json

 If internet permission is not taken to use HTTP Client, then what will happen ?


With out internet permission, it will throw UnknownHostException which is part of IOException.

 To use HTTPClient, which permission is required in an android application ?


android.permission.INTERNET is mandatory for any HTTPRequest, as we are fetching or posting information using internet or by using network connection.

 

What is intent ?


It is a kind of message or information that is passed to the components. It is used to launch an activity, display a web page, send sms, send email etc. There are two types of intents in android:
  1. Implicit Intent
  2. Explicit Intent

 

What are the life cycle methods of android Activity ?


  As an activity transitions from state to state, it is notified of the change by calls to the  
  following protected methods:

  1.     void onCreate(Bundle savedInstanceState)
  2.     void onStart()
  3.     void onRestart()
  4.     void onResume()
  5.     void onPause()
  6.     void onStop()
  7.     void onDestroy()
 
 Taken together, these seven methods define the entire lifecycle of an activity.

 

What is activity ?


Activity is like a frame or window in java that represents GUI. It represents one screen of android.

An Activity is an application component that provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or view a map. Each activity is given a window in which to draw its user interface. The window typically fills the screen, but may be smaller than the screen and float on top of other windows.

 

What are the core building blocks of android ?


The core building blocks of android are:
  • Activity - single screen on android mobile
  • View
  • Fragment 
  • Services – like Network Operation 
  •  Intent - To perform inter-communication between activities or services.
  •  Resource Externalization - such as strings and graphics.
  •  Notification signaling users - light, sound, icon, notification, dialog etc.
  •  Content Providers - They share data between applications
  •  How will you record a phone call in Android? How to get a handle on Audio Stream for a call in Android?
  •  Permissions.PROCESS_OUTGOING_CALLS: Allows an application to monitor, modify, or abort outgoing calls.

 

What are the advantages of android ?


Open-source: It means no licence, distribution and development fee.

Platform-independent: It supports windows, mac and linux platforms.

Supports various technologies: It supports camera, bluetooth, wifi, speech, EDGE etc. technologies.

Highly optimized Virtual Machine: Android uses highly optimized virtual machine for mobile devices, called DVM (Dalvik Virtual Machine).

 It is simple and powerful SDK.
 Licensing, Distribution or Development fee is not required.
 Easy to Import third party Java library.
 Supporting platforms are – Linux, Mac Os, Windows.
 Innovative products like the location-aware services, location of a nearby convenience store  etc., are some of  the additive facilities in Android. Components can be reused and replaced by  the application framework. 
 Optimized DVM for mobile devices.
 SQLite enables to store the data in a structured manner.
 Supports GSM telephone and Bluetooth, WiFi, 3G and EDGE technologies.
 The development is a combination of a device emulator, debugging tools, memory profiling and  plug-in for  Eclipse IDE.
 The customer will be benefited from wide range of mobile applications to choose.

 

What is Android 

Android is a stack of software for mobile devices which includes an Operating System, middleware and some key applications. The application executes within its own process and its own instance of Dalvik Virtual Machine. Many Virtual Machines run efficiently by a DVM device. DVM executes Java languages byte code which later transforms into .dex format files.