进程间通信之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);
}
本文介绍了Android中ContentProvider如何与BroadcastReceiver配合使用来实现进程间通信。详细讲解了通过ContentProvider进行数据传递的方法,以及如何利用BroadcastReceiver接收并处理这些数据。
1476

被折叠的 条评论
为什么被折叠?



