Thursday 12 May 2016

What is thread in java.

       Every executable program is called as thread. and there are two ways to create a thread :
1. By extending Thread class.
2. By implementing Runnable method.

Example of By extending Thread class :

class ThreadDemo extends Thread{
public void run(){
System.out.println("Thread class extended");
}
public static void main(String[] args ){
ThreadDemo TD=new ThreadDemo ();
TD.start();
}
}

Example of By implementing Runnable method :

class ThreadDemo implements Runnable{
public void run(){
System.out.println("Runnable class Implement");
}
public static void main(String[] args ){
ThreadDemo TD=new ThreadDemo ();
TD.start();
}
}

Which is best thread.

If we extends Thread class then we can not extend another class. And if we implement Runnable interface and in future if we want to extend any class then we can extend if we implement Runnable interface.







Saturday 23 April 2016

Exceptio error in android .gradle\caches\2.8\scripts\asLocalRepo37_tkshoj2mzpxt53d89bsykdde\cp_init\cache.properties (The system cannot find the file specified)

0pen c drive>user>uour user like your system name XYZ>.gradle>caches>2.8>script delete this folder and rebuild project

when i create fragment then it overlap on action bar

When you facing problem your action bar is getting overlapped by other activity.

Because you using frame layout add the following line in frame layout.

android:layout_marginTop="?attr/actionBarSize"


Like this it will resolve the problem of action bar overlapped actionbar.
in app_bar_main.xml
<FrameLayout    android:layout_width="match_parent"    android:layout_marginTop="?attr/actionBarSize"
android:layout_height="match_parent">  

Thursday 21 April 2016

how to create list view in android

1. Create Dispay.java class
package com.example.ListDisplay;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ListDisplay extends Activity {
   // Array of strings...
   String[] mobileArray = {"Android","IPhone","WindowsMobile","Blackberry","WebOS","Ubuntu","Windows7","Max OS X"};
   
   @Override
   protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
      
      ArrayAdapter adapter = new ArrayAdapter<String>(this, R.layout.activity_listview, mobileArray);
      
      ListView listView = (ListView) findViewById(R.id.mobile_list);
      listView.setAdapter(adapter);
   }
}

2. now create one xml file activity_main.xml
 xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical"
   tools:context=".ListActivity" >

   
      android:id="@+id/mobile_list"
      android:layout_width="match_parent"
      android:layout_height="wrap_content" >
   
 

3. Add following code in string file
xml version="1.0" encoding="utf-8"?>

    name="app_name">ListDisplay
    name="action_settings">Settings
4. create list item activity_listview
xml version="1.0" encoding="utf-8"?>


 xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/label"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:padding="10dip"
   android:textSize="16dip"
   android:textStyle="bold" >
List View

Wednesday 20 April 2016

What is intent in android.

An android Intent is an abstract description of an operation to be perform.It can be use with start activity to launch an activity, broadcastIntent so send it to any interested Broadcastreceiver  component.and startService(intent) or bindservice(intent,ServiceConnection,int) to communicate with a background Service.


Tuesday 19 April 2016

Content provider in android

Content provider manage access to the structured set of data.they encapsulate the data and provide mechanism to define the data security. Content providers are the standard interface that connect data in a process with code running in another process.

When you want to access data from content provider you use the object content resolver in context application to communicate with the provider as a costumer. 

FATAL EXCEPTION: main java.lang.IllegalArgumentException: Window type can not be changed after the window is added.

onAttchedToWndow() is used to disable home button in android
but in newer version this has been resolved

so comment the below code or remove





@Override
public void onAttachedToWindow()
  {
  this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG);
  super.onAttachedToWindow();
  }

service in android

A service is a android component that runs in background for long running operation without disturbing user or without interacting with UI. it keeps running even the application is closed.


Thread in android

Thread is concurrent unit of execution. It has its own call back stack for method being invoke, there argument and local variables. Each application having at least one thread is running when application started.the run times keeps its own thread in the system thread group.

There are two way to execute code in a new thread. you can either create sub class of Thread and override run() its own method or construct new thread and pass runnable to constructor  in either case start() method must be called to actually execute new thread .

Each thread has an integer priority that affect how the thread is scheduled by the OS. A new thread  inherit the priority of its parent,
.
for more details click here

What is multithreading in JAVA

Java is a multi threading language which means we can developed multi threaded program using Java. Multi thread program contain two or more parts working concurrently. and each part contains different task at the same time

Android Interview Question asked in interview.

1. Explain android components.

See ANS here: cleck here

2. What is thread in Android.

see ANS here : click here for Answer

3. What is  Service in android

See ANS here : click here for Answer

Android Application Components

There are four android components.
1. Activity
2. Service
3. Content Provider
4. Broadcast Receivers

Activity: Activity is nothing but the user interacting screen. Which user can interact with app.

Services: It handle background process of android without  disturbing user. And it is long running process.

Content Provider: This handle data and Database Management issue .

Broadcast Receiver :It handled the communication between android OS and Android Application.