Translate

Thursday, 8 September 2016

Top 5 best Android tools and utility apps

1.AppLock [Free with in app purchases]
2.DashLight [Free / $1.59]
3.GasBuddy  [Free]
4.Google Goggles [Free]
5.Google Translate  [Free]
6.Guitar Tuner Free [Free with in app purchases]

Wednesday, 7 September 2016

Android Fragment Tutorial


A Fragment speaks to a conduct or a bit of UI in an Activity. You can consolidate numerous parts in a solitary action to assemble a multi-sheet UI and reuse a section in different exercises. You can think about a piece as a secluded area of an action, which has its own particular lifecycle, gets its own info occasions, and which you can include or evacuate while the movement is running.
Here in this showing, we make two sections in a solitary window.One part shows ListView of names of individuals whose points of interest can be seen by selecting or tapping on them. For showing these points of interest, the Second piece is utilized.

So lets begin…

Requirements:- Android Studio

Step1:- Create an android studio venture with an unfilled action.

Step2:- Here is a substance of how we are going to continue with this venture

In the first place we are going to make

fragment_list.xml->This document just contains a ListView in LinearLayout which shows rundown of alternatives or rundown of names in our case.This record would be in res->layout organizer.

With this we make its controller document called UsersListFragment.java, so make another java record with this name

Second we are going to make

fragment_details.xml->This document contains basic TextView inserted again in a LnearLayout which is utilized for showing the subtle elements of chose thing.

With this we make its controller document called DetailFragment.java,so make another java record with this name.

Finally,we are going to make

complete_layout.xml->This record contains both the fragments.So now rather than activity_main.xml, MainActivity.java document calls upon complete_layout.xml,So erase or rename activity_main.xml.

With this we are going to code into MainActivity.java which is its controller record.
Step3:- In fragment_list.xml,a ListView is announced .

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >


    <ListView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/userslist"
        >
    </ListView>

</LinearLayout>

Step4:- make another java in the java->package_name called UsersListFragment.java which is the controller document of fragment_list.xml.

import android.app.Fragment;
    import android.content.Context;
    import android.os.Bundle;
    import android.view.LayoutInflater;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.AdapterView;
    import android.widget.ArrayAdapter;
    import android.widget.ListView;
 
    import java.util.ArrayList;
 
    public class UsersListFragment extends Fragment {
 
        private OnUserSelectedListener listener;
        ListView usersList;
        @Override
        public View onCreateView(LayoutInflater inflater, ViewGroup container,
                                 Bundle savedInstanceState) {
            View view = inflater.inflate(R.layout.fragment_list,
                    container, false);
 
            usersList = (ListView)view.findViewById(R.id.userslist);
            ArrayList<String> users = new ArrayList<String>();
            users.add("Vishal  Detake");
            users.add("Ashish Shriwastav");
            users.add("Sambhji Jatar");
            users.add("Tushar Handore");
            users.add("Ritesh Singh");
            ArrayAdapter<String> usersAdapter = new ArrayAdapter<String>(getActivity(),android.R.layout.simple_list_item_1,users);
            usersList.setAdapter(usersAdapter);
 
            usersList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                @Override
                public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                    getDetail(usersList.getItemAtPosition(position).toString());
                }
            });
            return view;
        }
 
        public interface OnUserSelectedListener {
            public void onUserSelected(String link);
        }
 
        @Override
        public void onAttach(Context context) {
            super.onAttach(context);
            if (context instanceof OnUserSelectedListener) {
                listener = (OnUserSelectedListener) context;
            } else {
                throw new ClassCastException(context.toString()
                        + "Activity Does not Implements Listener");
            }
        }
        @Override
        public void onDetach() {
            super.onDetach();
            listener = null;
        }
        public void getDetail(String name) {
            listener.onUserSelected(name);
        }
    }


Step5:- In fragment_details.xml,a TextView is utilized to announce the subtle elements.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
 
    <TextView
        android:id="@+id/detailsText"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center_horizontal|center_vertical"
        android:layout_marginTop="20dip"
        android:text="Nothing Selected"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textSize="30dip" />
 
</LinearLayout>

Step6:- So now moving to its java record, make another java in the java->package_name called DetailFragment.java which is the controller document of fragment_details.xml.

import android.app.Fragment;
        import android.os.Bundle;
        import android.view.LayoutInflater;
        import android.view.View;
        import android.view.ViewGroup;
        import android.widget.TextView;
 
public class DetailFragment extends Fragment {
 
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_details,
                container, false);
        return view;
    }
 
    public void setText(String name) {
        TextView view = (TextView) getView().findViewById(R.id.detailsText);
        view.setText(name);
    }
}

Step7:- In complete_layout.xml, 2 sections are pronounced implanted in LinearLayout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:baselineAligned="false"
    android:orientation="vertical" >
 
    <fragment
        android:id="@+id/listFragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        class="com.example.admin.fragmentexample.UsersListFragment" >
    </fragment>
 
    <fragment
        android:id="@+id/detailFragment"
        android:layout_width="match_parent"
 
        android:layout_height="wrap_content"
        class="com.example.admin.fragmentexample.DetailFragment" >
    </fragment>
 
</LinearLayout>

Step8:- So now we at last code into MainActivity.java.

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
 
public class MainActivity extends AppCompatActivity implements UsersListFragment.OnUserSelectedListener {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.complete_layout);
    }
 
    @Override
    public void onUserSelected(String name) {
        DetailFragment fragment = (DetailFragment) getFragmentManager()
                .findFragmentById(R.id.detailFragment);
        fragment.setText(name);
    }
}


Saturday, 3 September 2016

Architecture of Andriod

Architecture of Android Diagram 




Applications -:

You will discover all the Android application at the top layer. You will compose your application to be introduced on this layer as it were. Case of such applications are Contacts Books, Browser, Games, Home and so forth.

Application Framework -:

The Application Framework layer Is Second Layer Of Android. Application engineers are permitted to make utilization of these administrations in their applications.
·      Activity Manager − Controls all parts of the application lifecycle and movement stack.
·      Content Providers − Permits applications to distribute and impart information to different applications.
·      Resource Manager − Gives access to non-code implanted assets, for example, strings, shading settings and UI formats.
·      Notifications Manager − Permits applications to show cautions and warnings to the client.
·      View System An extensible arrangement of perspectives used to make application UIs.

Android Libraries -:

 

·      SQLiteIt is used to access data published by content providers and includes SQLite database management classes
·      SSL It is used to provide internet security
·      OpenGL It is used to provide Java interface to the OpenGL/ES 3D graphics rendering API
·      Media framework − It is used to provides different media codecs which allow the recording and playback of different media formats
·            WebKit It is the browser engine used to display internet content or HTML content

Android Runtime -:


This is the third area of the engineering and accessible on the second layer from the base. This area gives a key part called Dalvik Virtual Machine which is a sort of Java Virtual Machine uncommonly outlined and enhanced for Android.

The Dalvik VM makes utilization of Linux center components like memory administration and multi-threading, which is natural in the Java dialect. The Dalvik VM empowers each Android application to keep running in its own particular procedure, with its own example of the Dalvik virtual machine.

The Android runtime additionally gives an arrangement of center libraries which empower Android application engineers to compose Android applications utilizing standard Java programming dialect.

Linux kernel -:

 


At the base of the layers is Linux - Linux 3.6 with around 115 patches. This gives a level of reflection between the gadget equipment and it contains all the crucial equipment drivers like camera, keypad, show and so on. Likewise, the part handles every one of the things that Linux is decent at, for example, organizing and an unfathomable exhibit of gadget drivers, which remove the torment from interfacing to fringe equipment.

Friday, 2 September 2016

What is Activity Life Cycle of Android ?

 Activity Life Cycle of Android 






OnCreate
This is the first method to be called when an activity is created. OnCreate is always overridden to perform any startup initializations that may be required by an Activity such as:

·       Creating views
·       Initializing variables
·       Binding static data to lists
OnCreate takes a Bundle parameter, which is a dictionary for storing and passing state information and objects between activities If the bundle is not null, this indicates the activity is restarting and it should restore its state from the previous instance. The following code illustrates how to retrieve values from the bundle:
protected override void OnCreate(Bundle bundle)
{
   base.OnCreate(bundle);

   string intentString;
   bool intentBool;

   if (bundle != null)
   {
      intentString = bundle.GetString("myString");
      intentBool = bundle.GetBoolean("myBool");
   }

   // Set our view from the "main" layout resource
   SetContentView(Resource.Layout.Main);
}
Once OnCreate has finished, Android will call OnStart.
OnStart
This method is always called by the system after OnCreate is finished. Activities may override this method if they need to perform any specific tasks right before an activity becomes visible such as refreshing current values of views within the activity. Android will call OnResume immediately after this method.
OnResume
The system calls this method when the Activity is ready to start interacting with the user. Activities should override this method to perform tasks such as:
·       Ramping up frame rates (a common task in game building)
·       Starting animations
·       Listening for GPS updates
·       Display any relevant alerts or dialogs
·       Wire up external event handlers
As an example, the following code snippet shows how to initialize the camera:
public void OnResume()
{
    base.OnResume(); // Always call the superclass first.

    if (_camera==null)
    {
        // Do camera initializations here
    }
}
OnResume is important because any operation that is done in OnPause should be un-done in OnResume, since it’s the only lifecycle method that is guaranteed to execute after OnPause when bringing the activity back to life.
OnPause
This method is called when the system is about to put the activity into the background or when the activity becomes partially obscured. Activities should override this method if they need to:
·       Commit unsaved changes to persistent data
·       Destroy or clean up other objects consuming resources
·       Ramp down frame rates and pausing animations
·       Unregister external event handlers or notification handlers (i.e. those that are tied to a service). This must be done to prevent Activity memory leaks.
·       Likewise, if the Activity has displayed any dialogs or alerts, they must be cleaned up with the .Dismiss() method.
As an example, the following code snippet will release the camera, as the Activity cannot make use of it while paused:
public void OnPause()
{
    base.OnPause(); // Always call the superclass first

    // Release the camera as other activities might need it
    if (_camera != null)
    {
        _camera.Release();
        _camera = null;
    }
}
There are two possible lifecycle methods that will be called after OnPause:
1.    OnResume will be called if the Activity is to be returned to the foreground.
2.    OnStop will be called if the Activity is being placed in the background.
OnStop
This method is called when the activity is no longer visible to the user. This happens when one of the following occurs:
·       A new activity is being started and is covering up this activity.
·       An existing activity is being brought to the foreground.
·       The activity is being destroyed.
OnStop may not always be called in low-memory situations, such as when Android is starved for resources and cannot properly background the Activity. For this reason, it is best not to rely on OnStop getting called when preparing an Activity for destruction. The next lifecycle methods that may be called after this one will be OnDestroy if the Activity is going away, or OnRestart if the Activity is coming back to interact with the user.
OnDestroy
This is the final method that is called on an Activity instance before it’s destroyed and completely removed from memory. In extreme situations Android may kill the application process that is hosting the Activity, which will result in OnDestroy not being invoked. Most Activities will not implement this method because most clean up and shut down has been done in theOnPause and OnStop methods. The OnDestroy method is typically overridden to clean up long running resources that might leak resources. An example of this might be background threads that were started in OnCreate.
There will be no lifecycle methods called after the Activity has been destroyed.
OnRestart
This method is called after your activity has been stopped, prior to it being started again. A good example of this would be when the user presses the home button while on an activity in the application. When this happens OnPause and then OnStopmethods are called, and the Activity is moved to the background but is not destroyed. If the user were then to restore the application by using the task manager or a similar application, Android will call the OnRestart method of the activity.