Android Interface Definition Language (aidl)The following steps are required to establish an adjoining service using Aidl
1. Create a. aidl fileThis file uses the method signature to define the language interface
2. Implement this interfaceThe Android SDK Tool uses the Java language to generate an interface based on your. aidl file This interface has an
Android has four components: Activity, broadcast explorer, service, and content providers;
Today, I will introduce the service first. The service function is similar to the activity (this will be described in detail in subsequent articles). The service can be said to be an a
provides the getservice () method to the client, which can be used to obtain the current instance of the LocalService. This allows the client to call public methods in the service. For example, a client can call the getrandomnumber () method of the server.
The following activity code binds the LocalService and calls the getrandomnumber () method of the service when you click a button:
Public class bindinga
, broadcast the playlist name and index, used to merge the new playlist @ override public void onplaymusicindexchanged (string playlistname, int musicindex) throws RemoteException {// todo auto-generated method stub }}(5) generate a serviceconnection subclass on the activity side for bindservice to connect to the serverPrivate class serconn implements serviceconnection {@ overridepublic void onserviceconnected (componentname name, ibinder Service) {//
Brief introduction:This article describes how developers ' apps use media storage services (including Mediascanner, Mediaprovider, and media information parsing) in Android, and how to update the app's new or modified files to the media database, How to hide the files generated by the app in the multimedia application, how to monitor the changes of the media database and so on.Android has an original set of media storage services, the process name is
application and other applications to execute actions and generate events. Using intent, You can activate three core components of the Android app: Activity, service, and broadcast receiver.
Intent can be divided into explicit intent and implicit intent:
1 ). explicit intent: Call intent. setcomponent () or intent. the setclass () method specifies the component name or the intent of the class object as the
Now, to create an application, you need to push the notification to the client. I thought of using c2dm. However, the test was not very reliable and the efficiency was not high. But the occasional opportunity to find this site: http://www.push-notification.org/index.php
First, we need to declare that many Android apps in China now have the push notification function, but most of them arePull ModeThat is, the client actively requests data from the ser
Intentservice Service is also a service of wirelessly, it inherits with the service, but unlike Servcie, it opens a new thread to handle all requests, does not need the UI waits for processing, the Onstartcommand method sends all requests to the work queue, , and then sent by the work queue to onhandlerintent for processing1.interservice by default, a new thread
Activity appears to be an application's eye, providing a window of interaction with the user.Broadcastreceiver seemed to be ears, receiving intent from all sides.The service is running in the background.A service is a section of a life cycle, without a user-interface program. A good example of this is the one that is being played from the playlistThe media player that plays the song. In a media player appli
Exploration of positioning service (GPS) on Android platform)
Note: Do not forget to add permissions for all of the following operations:
Locationmanager
You can use locationmanager to locate, track, and approaching devices. It does not need to be instantiated directly. We can use context. getsystemservice (context. location_service). To obtain the locationmanager instance.
Common attributes and Metho
), other oncreate, onbind, onunbind, ondestory can only be called once in a lifecycle. For details, see Android Service (1) -- service.
Iii. bindservice Lifecycle
Like an activity, a service can be used to change the state of the lifecycle method, but less than the activity method, the
Binding Service Usage
When binding services, the most important thing is to define the interface returned by the onbind () callback method. There are three methods:
1. inherit the binder class
2. Use messenger
3. Use aidl
The method 1 and 2 is analyzed here.
1. inherit the binder class
If your service is a private service of your application and runs in the same
There are two main ways to use service in Android, by invoking the StartService method of the context or by invoking the Bindservice method of the context, this article only discusses the use of StartService, Does not involve any Bindservice method invocation scenarios.When we call the StartService method of the context, we start the service, and the
The example in this article describes how the Android implementation determines whether a service is running. Share to everyone for your reference, specific as follows:
/**
* The method of determining whether a service is running
* *
@param mcontext
* @param serviceName
* is the package name + The class name of the
Android Serial Port Data Reading service, android serial port
2016-09-1813: 10: 03
Inherit from the Service and define the abstract method onDataReceived. The subclass obtains the received data callback by implementing the abstract method.
1 package com.zrsoft.liftad.serialport; 2 3 import java.io.File; 4 import java
Transferred from: http://blog.csdn.net/luoshengyang/article/details/7857163In describing the relationship between Android applications and Surfaceflinger Services, it is mentioned that every android application with a UI needs to The Surfaceflinger service establishes a connection so that the Surfaceflinger service
Summary
If you have never touched the service before, you can have a general understanding of the following content. After using the service, read this chapter to learn more deeply.
Service is one of the four Android components, and the rest are activity, BroadcastReceiver, and Content Provider. A
There are several important components in Android, one of which is service. This is a component without a UI and can be used as a backend service. Of course, you can use intent to start it. It can also be bound to a host object (caller, usually activity) for use,
Note:1. The service in
AlarmManager, a system service provided by Android)
This section introduces:
This section describes AlarmManager In the Android system service ),
In addition to the development of mobile phone alarm clocks, it is more often used as a global timer, usually with the Service
Android service Summary
1. Start a service using the startservice method. The service cannot start itself. If you start an activity in a service, you must declare a brand new activity TASK. Services started using the startservice method will not die as the startup components
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.