1.monkey的使用
2.Log的使用
3.Android四大组件之Activity
Activity是android应用程序的一个界面,是用户可见与用户进行交互的组件,可以通过使用一个Activity它实现各种功能
Service运行在后台,负责处理一些用户看不到,却又耗费时间的任务,比如播放音乐,下载数据等。
Content Provider 由于不同应用数据在android中都是私有的,Content Provider为存储和获取数据提供统一的接口(类似API)
可以在不同的应用间共享数据
Broadcast Receiver负责对外部事件进行相应,比如来短信,来电话等各种事件发生时要进行对应的操作。
四大组件都要在Manifest.xml中进行注册才能使用
Intent,可以通过传递Intent启动一个Activity,可以通过传递Intent启动一个Service,通过Intent新加入一个广播Broadcast Receiver,就像小纸条一样在各组件间传递信息。
Intent _intent=new Intent(); //Intent的构造函数可以为空,但若为空,但后面要有setClass setAction setData等来确定Intent的属性
setClass(当前环境----this,要启动的Act的类class)
或者直接在构造函数中加上属性比如 Intent _intent=new Intent(FirstActivity.this,SecondActivity.class);从一个Act传到另一个Act
或者Intent _intent=new Intent(Intent.ACTION_DIAL); _intent.setData(Uri.parse("tel:13486090167"));
激活Activity可以用startActivity(_intent);
也可以用startActivityForResult(_intent,1234); 这个Intent激活的Activity里可以用setResult()方法来进行返回值的设置,在第一个Act里用复写onActivityResult()方法进行返回值的接收
4.Activity生命周期
onCreate进程创建
onStart开始进程
onResume获得焦点
onPause失去焦点
onStop不可见
onDestroy进程销毁
onRestart
onSaveInstanceState 可以在Activity关闭时数据的存储
在onRestoreInstanceState 或者在onCreate中进行 数据的恢复
可以用finsh()关闭当前Activity finishActivity()关闭Activity
5.Android四大组件之Service
2.在要启动的Service中重写★onBind★方法来返回一个IBinder对象,该对象应该有一个方法getService来返回这个Service类,以便继续对Service进行操作,所以继承了IBinder对象的一个类来满足此方法
3.在onServiceConnected中获得返回的Binder
4.通过此Binder的getService方法获得服务Service
5.通过该Service来调用服务的方法达到操控Service的目的
package com.zys.service;
import com.zys.service.BindService.MyBinder;
public class MainActivity extends Activity {
private Button startBtn;
private Button stopBtn;
private boolean flag;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
flag = false;
//设置
startBtn = (Button)this.findViewById(R.id.startBtn);
stopBtn = (Button)this.findViewById(R.id.stopBtn);
startBtn.setOnClickListener(listener);
stopBtn.setOnClickListener(listener);
}
private OnClickListener listener = new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch (v.getId()) {
case R.id.startBtn:
bindService();
break;
case R.id.stopBtn:
unBind();
break;
default:
break;
}
}
};
private void bindService(){
Intent intent = new Intent(MainActivity.this,BindService.class);
bindService(intent, conn, Context.BIND_AUTO_CREATE);
}
private void unBind(){
if(flag == true){
unbindService(conn);
flag = false;
}
}
private ServiceConnection conn = new ServiceConnection() {
@Override
public void onServiceDisconnected(ComponentName name) {
// TODO Auto-generated method stub
}
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
// TODO Auto-generated method stub
MyBinder binder = (MyBinder)service;
BindService bindService = binder.getService();
bindService.MyMethod();
flag = true;
}
};
}
被调用的服务:
package com.zys.service;
import java.io.FileDescriptor;
import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.os.IInterface;
import android.os.Parcel;
import android.os.RemoteException;
import android.util.Log;
public class BindService extends Service {
private static final String TAG = "BindService";
public void MyMethod(){
Log.i(TAG, "BindService-->MyMethod()");
}
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return myBinder;
}
public class MyBinder extends Binder{
public BindService getService(){
return BindService.this;
}
}
private MyBinder myBinder = new MyBinder();
}
6.adb工具
7.一些控件Widget的使用
int position, long id) {