进程间通信之ContentProvider+BroadCastReceiver

进程间通信之ContentProvider+BroadCastReceiver

1. 将数据通过参数传递给ContentProvider组件。

2. ContentProvider调用CAE处理请求。

3. CAE将响应通过BroadCast传递给UI。

4. 在此之前UI须注册BroadCastReceiver。

 

String[] projection = null;
String selection = null;
String sortOrder = null;
String[] selectionArgs = null;
selectionArgs = new String[3];
selectionArgs[0] = gateIP;
selectionArgs[1] = userName;
selectionArgs[2] = password;
getContentResolver().query(Login.CONTENT_URI, projection, selection, selectionArgs, sortOrder);
CAEReceiver caeReceiver;
class CAEReceiver extends BroadcastReceiver {
 @Override
 public void onReceive(Context context, Intent intent) {
  String msg = intent.getStringExtra("msg");
  UHomeUtil.log("CAEReceiver.onReceive>>\n" + msg);

  if(gnmk == Gnmk.JDKZ)
  {
   Intent it = new Intent();
   it.setClass(UHomeMain.this, JdkzAct.class);
   startActivity(it);
  }
  UHomeMain.this.unregisterReceiver(this);
 }
}
 public static final String ACTION_CAE = "android.intent.action.CAE_BROADCAST";
caeReceiver = new CAEReceiver();
IntentFilter filter = new IntentFilter();
filter.addAction(GConst.ACTION_CAE);
registerReceiver(caeReceiver, filter);
public void sendCAEBroadCast(String msg)
{
 Intent mIntent = new Intent(GConst.ACTION_CAE); 
    mIntent.putExtra("msg", msg); 
    this.getContext().sendBroadcast(mIntent);
}

 

 

你可能感兴趣的:(进程间通信之ContentProvider+BroadCastReceiver)