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().