Saturday, March 19, 2011

Services, BroadCast Reciever and Content Provider

1) What is Services ?
Answer :- A service doesn't have a visual user interface, but rather runs in the background for an indefinite period of time. For example, a service might play background music as the user attends to other matters, or it might fetch data over the network or calculate something.

2) What is Life Cycle of Services ?
Answer :- There are two ways to start a services.
Context.startService()   Context.bindService()


3) What is difference between Context.startService() and Context.bindService() ?
Answer :-
Context.startService() -> A facility for the application to tell the system about something it wants to be doing in the background (even when the user is not directly interacting with the application). This corresponds to calls to Context.startService(), which ask the system to schedule work for the service, to be run until the service or someone else explicitly stop it.
Context.bindService() -> A facility for an application to expose some of its functionality to other applications. This corresponds to calls to Context.bindService(), which allows a long-standing connection to be made to the service in order to interact with it.



4) What is Bound Services ?
Answer :- A bound service is the server in a client-server interface. A bound service allows components (such as activities) to bind to the service, send requests, receive responses, and even perform interprocess communication (IPC). A bound service typically lives only while it serves another application component and does not run in the background indefinitely.


5) What is BroadCast Reciever ?
Answer :- A broadcast receiver is a component that does nothing but receive and react to broadcast announcements. Many broadcasts originate in system code — for example, announcements that the timezone has changed, that the battery is low, that a picture has been taken, or that the user changed a language preference. All receivers extend the BroadcastReceiver base class. A BroadcastReceiver object is only valid for the duration of the call to onReceive(Context, Intent). Once your code returns from this function, the system considers the object to be finished and no longer active.

6) What is Content Provider ?
Answer :- Content providers store and retrieve data and make it accessible to all applications. They're the only way to share data across applications. For example, the contacts data is used by multiple applications and must be stored in a content provider. If you don't need to share data amongst multiple applications you can use a database directly via SQLiteDatabase.
Content Provider is achived by a ContentResolver interface. Requests to ContentResolver are automatically forwarded to the appropriate ContentProvider instance. The primary methods that need to be implemented are:

  • onCreate() which is called to initialize the provider
  • query(Uri, String[], String, String[], String) which returns data to the caller
  • insert(Uri, ContentValues) which inserts new data into the content provider
  • update(Uri, ContentValues, String, String[]) which updates existing data in the content provider
  • delete(Uri, String, String[]) which deletes data from the content provider
  • getType(Uri) which returns the MIME type of data in the content provider
Data access methods (such as insert(Uri, ContentValues) and update(Uri, ContentValues, String, String[])) may be called from many threads at once, and must be thread-safe. Other methods (such as onCreate()) are only called from the application main thread.

7) Give a small example of Content Provider ?
Answer :- 
In ContentUserDemo.java
package org.example.contprov;
import java.util.ArrayList;
import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.Contacts.People;
import android.util.Log;
import android.widget.ArrayAdapter;
import android.widget.ListView;

public class ContentUserDemo extends Activity {
private static final String TAG = "ContentUserDemo";
private ArrayList<String> list;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Get content provider and cursor
ContentResolver r = getContentResolver();
Cursor cursor = r.query(People.CONTENT_URI, null, null, null, null);

// Let activity manage the cursor
startManagingCursor(cursor);
Log.d(TAG, "cursor.getCount()=" + cursor.getCount());

// Get value from content provider
int nameIndex = cursor.getColumnIndexOrThrow(People.NAME);
int numberIndex = cursor.getColumnIndexOrThrow(People.NUMBER);

cursor.moveToFirst();
list = new ArrayList<String>();
do {
String name = cursor.getString(nameIndex);
String number = cursor.getString(numberIndex);
list.add(name + ": " + number);
} while (cursor.moveToNext());

// Get the list view
ListView listView = (ListView) findViewById(R.id.listView);
ArrayAdapter<String> aa = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, list);
listView.setAdapter(aa);
}
}

In layout/main.xml :- This layout just dumps the data in a ListView. One interesting part is linking the ArrayAdapter to the ListView, in the previous file.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView android:layout_width="wrap_content"
android:layout_height="wrap_content" android:id="@+id/listView"></ListView>
</LinearLayout>

AndroidManifest.xml :- Don't forget to ask for permission to read the contacts from the system Content Provider.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.example.cp" android:versionCode="1" android:versionName="1.0.0">
<uses-permission android:name="android.permission.READ_CONTACTS" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".ContentUserDemo" android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Results :- You should see the list of people from your Contacts printed in your own application.







47 comments:

  1. Beautiful Description... :)
    Thanks a lot...

    ReplyDelete
  2. Useful descriptions

    ReplyDelete
  3. Yes. You are right Geetha Devi. This has much useful information and nice content.

    Informatica Training in Chennai | Informatica Training institute in Chennai

    ReplyDelete
  4. I read your blog everything is helpful and effective.
    Thanks for sharing with us.
    App V Training From India

    Sailpoint Training From India

    ReplyDelete
  5. In the event that you run a business and that too a huge one, you can’t manage to commit mistake in QuickBooks Support and that is where QB Payroll plays its part.

    ReplyDelete
  6. QuickBooks Enterprise Technical Support Number troubling you? Are you currently fed up with freezing of QuickBooks? If yes, you then have browsed off to the right place.

    ReplyDelete
  7. How to contact QuickBooks Payroll support?
    Different styles of queries or QuickBooks related issue, then you're way in the right direction. You simply give single ring at our toll-free intuit QuickBooks Online Payroll Contact Number . we are going to help you right solution according to your issue. We work on the internet and can get rid of the technical problems via remote access not only is it soon seeing that problem occurs we shall fix the same.

    ReplyDelete
  8. We provide QuickBooks Desktop Payroll Support Phone Number team in terms of customers who find QuickBooks Payroll hard to use. As Quickbooks Payroll customer care we make use of the responsibility of resolving all of the issues that hinder the performance regarding the exuberant software.

    ReplyDelete
  9. QuickBooks Help Number is the better platform for smaller businesses. QuickBooks technical support number helps you to run all QuickBooks Payroll services boosting your online business quickly.

    ReplyDelete
  10. Any QuickBooks user faces any sort of identified errors in their daily accounting routine; these errors may differ from 1 another to a large degree, so our dedicated QuickBooks Support Phone Number Pro-Advisers are very well loaded with their tools and expertise to give most effective resolutions very quickly to the customers.

    ReplyDelete
  11. QuickBooks Enterprise tech support team enables you to manage your organization operations by getting you the latest versions of QuickBooks Enterprise like QuickBooks Enterprise 2019. Just dial QuickBooks Enterprise Support Number to understand the professionals and cons of accounting software with the help of our QuickBooks tech support members.

    ReplyDelete
  12. Help and support from QB Enterprise is tremendous specially considering that QuickBooks Enterprise Support Number will also help you track all the data, amount etc. of donors, funds and so forth and so on.

    ReplyDelete
  13. Our QuickBooks Technical Support is obtainable for 24*7: Call @
    QuickBooks Support Phone Number any time
    Take delight in with an array of outshined customer service services for QuickBooks via quickbooks technical support contact number at any time and from anywhere. It signifies that one can access our tech support for QuickBooks at any moment. Our backing team is dedicated enough to bestow you with end-to-end QuickBooks solutions when you desire to procure them for every single QuickBooks query.

    ReplyDelete
  14. Non-Profit: Running a non-profit organisation may also be a troublesome task as well as monitored properly. Help and support from QuickBooks Enterprise Tech Support Phone Number is tremendous specially considering that it will also help you track all the data, amount etc. of donors, funds and so forth and so on.

    ReplyDelete
  15. Support For QuickBooks helps to make the process far more convenient and hassle free by solving your any QuickBooks issues and error in only an individual call. We offer excellent tech support team services once we have the highly experienced and certified professionals to provide you the gilt-edge technical support services like-

    ReplyDelete
  16. If you are facing some other problems with your QuickBooks Technical Support Phone Number, you'll be able to also make instant calls. Your queries are certain to get resolved without the delays.

    ReplyDelete
  17. complete awareness of the demand of technical assistance produced by QuickBooks users. Our research team is often prepared beforehand with the the most suitable solutions that are of good help much less time consuming. Their pre-preparedness helps them extend their hundred percent support to any or all the entrepreneurs as well as individual users of QuickBooks. As QuickBooks Technical Support Number executives for QuickBooks, we assure our round the clock availability at our technical contact number.

    ReplyDelete
  18. For QuickBooks Support Phone Number system configuration requires as the very least a 1.8 GHz processor, 1 GB of disk space, 256 MB of RAM for a specific user, whereas, it requires 512 MB of RAM for multiple users.

    ReplyDelete
  19. Business proprietor these days completely rely on QuickBooks in order to avoid the effort for the types of work. The popular Support For QuickBooks versions: Pro Advisor, Payroll and Enterprise have brought a revolution in the current business competition .

    ReplyDelete
  20. Simply store your web visitors and vendors all information and many other things. QuickBooks Support Number is often a wonderful and well-known name because of its 100% accuracy, certainty, and reliability.

    ReplyDelete
  21. Our instantly QuickBooks Premier Support Number team is ideal in taking down every QuickBooks error. We are able to assure you this with a warranty. Call our Quickbooks Tech Support Phone Number . Our QuickBooks Premier Support Number team will attend you.

    ReplyDelete

  22. You may encounter QuickBooks Error Code 6000-301 when wanting to access/troubleshoot/open the organization file in your QuickBooks. Your workflow gets hindered with an Error message that says– “QuickBooks Desktop tried to gain access to company file. Please try again.”

    ReplyDelete
  23. No need to worry, just make a Call on our QuicKbooks Customer Support Phone Number and get assist by technical support advisors. You may also connect via mail or chat to Quickbooks expert’s team 24/7.

    ReplyDelete
  24. Hope now you recognize that just how to interact with QuickBooks enterprise support phone number and QuickBooks Enterprise Tech Support Number. We've been independent alternative party support company for intuit QuickBooks, we do not have just about any link with direct QuickBooks, the employment of name Images and logos on website simply for reference purposes only.

    ReplyDelete
  25. QuickBooks Support Toll-Free offers an extensive financial solution, where it keeps your entire business accounting requirements in one single place. From estimates to bank transfers, invoicing to tracking your expenses and staying on top of bookkeeping with regards to tax time, it really is prepared for many from it at one go. A total package to create you clear of Financial accounting and back office worries any time to make sure you concentrate on your own expert area and yield potential development in business.

    ReplyDelete
  26. QuickBooks Payroll Technical Support Number deductions and year-end tax filings could be daunting and consume most of your productive time. To help you save the hassle of manually creating payroll and filing tax, Intuit, Inc.

    ReplyDelete
  27. QuickBooks Support Phone Number get you one-demand technical help for QuickBooks. QuickBooks allows a number of third-party software integration. QuickBooks software integration is one of the most useful solution provided by the software to handle the accounting tasks in a simpler and precise way. You should not be worried about the costing with this software integration because it offers a wide range of pocket-friendly plans which can be used to control payroll with ease.

    ReplyDelete
  28. In today’s scenario individuals have got really busy inside their lives and work. QuickBooks Tech Support Phone Number want to grow and learn as many new things as they possibly can. This drive has initiated a feeling of awareness amongst individuals and thus they find approaches to invent alternatives for daily tasks.

    ReplyDelete
  29. Positive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. 스포츠중계

    ReplyDelete
  30. The error comes while you are in the middle of searching for something online and you see banking error 9999. The error can cause the system to hang, run slowly or even stop working. Also when the accounting professionals are trying to update the bank information, they can get entangled with this error. If you would like to learn how to Troubleshoot Quickbooks Error 9999, you can continue reading this blog.

    ReplyDelete
  31. This comment has been removed by the author.

    ReplyDelete
  32. It is actually a great and helpful piece of information. I am satisfied that you simply shared this helpful information with us. Please stay us informed like this. Thanks for sharing.





    Android Training Institute in Chennai | Android Training Institute in anna nagar | Android Training Institute in omr | Android Training Institute in porur | Android Training Institute in tambaram | Android Training Institute in velachery

    ReplyDelete
  33. Are you looking for the best Azure training in Chennai here is the best suggestion for you, Infycle Technologies the best Software training institute to study to also other technical courses like Cyber Security, Graphic Design and Animation, Block Security, Java, Cyber Security, Oracle, Python, Big data, Azure, Python, Manual and Automation Testing, DevOps, Medical Coding etc., with technical trainers with amazing training with a peaceful environment. And we also provide 100+ Live Practical Sessions and Real-Time scenarios which helps you to easily get through the interviews in top MNC’s. for more queries approach us on 7504633633, 7502633633.

    ReplyDelete