通过bindService ()方法启动的服务

  初始化结束后系统会调用该方法,用来绑定传递给bindService 的Intent 的对象。注意:多次调用bindService()时,如果该服务已启动则不会再触发此方法

  IBinder onBind(Intent intent)

  用户调用unbindService()时系统调用此方法,Intent 对象同样传递给该方法

  boolean onUnbind(Intent intent)

  如果有新的客户端连接至该服务,只有当旧的调用onUnbind()后,新的才会调用该方法

  void onRebind(Intent intent)

  补充:onCreate(Bundle savedInstanceState)与onSaveInstanceState(Bundle savedInstanceState)配合使用,见如下代码,达到显示activity被系统杀死前的状态

  @Override

  public void onCreate(Bundle savedInstanceState) {

  super.onCreate(savedInstanceState);

  if (null != savedInstanceState) {

  String _userid = savedInstanceState.getString("StrUserId");

  String _uid = savedInstanceState.getString("StrUid");

  String _serverid = savedInstanceState.getString("StrServerId");

  String _servername = savedInstanceState.getString("StrServerName");

  int _rate = savedInstanceState.getInt("StrRate");

  //updateUserId(_userid);

  //updateUId(_uid);

  //updateServerId(_serverid);

  //updateUserServer(_servername);

  //updateRate(_rate);

  }

  }

  @Override

  protected void onSaveInstanceState(Bundle savedInstanceState) {

  super.onSaveInstanceState(savedInstanceState);

  savedInstanceState.putString("StrUserId", getUserId());

  savedInstanceState.putString("StrUid", getUId());

  savedInstanceState.putString("StrServerId", getServerId());

  savedInstanceState.putString("StrServerName", getServerName());

  savedInstanceState.putInt("StrRate", getRate());

  }

  引发activity摧毁和重建的其他情形

  除了系统处于内存不足的原因会摧毁activity之外, 某些系统设置的改变也会导致activity的摧毁和重建. 例如改变屏幕方向(见上例), 改变设备语言设定, 键盘弹出等.