Make Custom Android Launcher

Image
There are thousands of Android Launcher available in Play Store. Each and every Android mobile user loves to customize their mobile with different Android Launcher. If you want to develop your own launcher, this post helps you to fulfill your wish. In this post, you will find a demo launcher with layout and code which include many features like Drag & Drop , rearrange the installed application, change the background wallpaper etc. Here is an example of demo launcher which display all the installed applications in 3*3 Grid View format compatible to all devices. First of all we need to find all the installed applications from device so we should implement a subclass of AsyncTaskLoader that loads the currently installed applications from the package manager. If you want to display all the installed applications in  List View you can use official Android Developer reference .

Android Services

  • Services are always running in the background, which performs long operation.
  • They don't have any UI(User Interface) Components.
  • By default, Services and Activities both are runs in same application.
  • An example of a service is, music player that plays music in background.
  • Two states of Services are,
    1. Started : A service starts by calling startService() method and runs in background until it destroyed.
    2. Bounded An application component can interact with the service using bounded service. The bindService() method used to bind the component with service. The bounded service should be Unbind before destroying that service.


In Layout file(mainActivity.xml):
      <Button android:id="@+id/btn1"
              android:onClick="service_start"/>
      <Button android:id="@+id/btn2"
              android:onClick="service_stop"/>


In subclass of Activity(MainActivity.java):
// To start the service
      public void service_start(View v)
        {
             startService(new Intent(getBaseContext(), CustomService.class));
         }
// To stop the service
       public void service_stop(View v)
        {
             stopService(new Intent(getBaseContext(), CustomService.class));
        }

Create subclass of Service named CustomService.class file,
       public class CustomService extends Service {
           @Override
             public IBinder onBind(Intent i) {
                return null;   // null represents No components are bind to service
              }
           @Override
            public int onStartCommand(Intent i, int flag, int startId) {
                Toast.makeText(this, "Service Successfully Started", Toast.LENGTH_LONG).show();
                 return 1;
              }
            @Override
           public void onDestroy() {
               super.onDestroy();
               Toast.makeText(this, "Service Successfully Destroyed", Toast.LENGTH_LONG).show();
              }
           }
In order to use service, register it to AndroidManifest.xml
      <application>
            <service android:name = ".CustomService" />
      </application>

Comments

Popular posts from this blog

Make Custom Android Launcher

Layouts for Fragment