Android development Notes-3(Activity, Intents, and Tasks, Service, Content provider)

Summary:Activity, Intents, and Tasks, Service, Content provider

-Android introduces a richer and more complex approach by supporting multiple application entry points. Android programs should expect the system to start them in different places, depending on where the user is coming from and what she wants to do next

Activity, Intents, and Tasks

-An Android activity is both a unit of user interaction—typically filling the whole screen of an Android mobile device—and a unit of execution

-The unit of communication is the  Intent class. An  Intent represents an abstract description of a function that one activity requires another activity to perform, such as taking a picture.

public class TestActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
-The  onCreate method kicks off the life cycle of the  Activity 
 -An  Activity interacts with the Android runtime to implement key aspects of the application life cycle. Each activity can also be independently configured, through a  Context class

-Each activity in an Android application is largely separate from other activities. The code that implements one activity does not directly call methods in the code that implements another activity.

-Instead of a user interface flow control based on method calls, applications describe an Intent that they want to execute and ask the system to find one that matches. 


Service

-The Android  Service class is for background tasks that may be active but not visible on the screen.

-The Android platform avoids reclaiming service resources, so once a service starts, it is likely to be available unless memory gets extremely constrained.

Content provider

-Content provider components are roughly analogous to a RESTful web service: you find them using a URI, and the operations of a  ContentProvider subclass parallel RESTful web operations such as putting and getting data.

-REST stands for “Representational State Transfer.”

-Content provider components are the heart of the Android content model: by providing a  ContentProvider , your application can share data with other applications and manage the data model of an application.

-A companion class,  ContentResolver , enables other components in an Android system to find content providers.

-Due to its importance in Android, we provide a brief introduction here to writing a client that uses a content provider

-Activities access specific content provider instances using the  ContentResolver class and associated URLs as follows:

// code from an activity method
ContentProviderClient client = getContentResolver().
acquireContentProviderClient("content://contacts/people");
ContentProvider provider = client.getLocalContentProvider();
-Together with the  Activity component of an Android application, content providers provide the necessary parts of a Model-View-Controller (MVC) architecture.



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值