Android &引用;readBundle:bad magic数字“;从包中获取字符串时出错

Android &引用;readBundle:bad magic数字“;从包中获取字符串时出错,android,android-intent,android-broadcast,Android,Android Intent,Android Broadcast,我正在将包从一个类传递到另一个类。但是当收到它时,我得到了类似“readBundle:bad magic number”的错误。下面是一段代码片段 从类A传递包: Intent intent = new Intent(); Bundle b1=new Bundle(); b1.putString("STORE_STATUS", "true"); b1.putParcelableArrayList("ParticularStoreInfo", particularStoreInf

我正在将包从一个类传递到另一个类。但是当收到它时,我得到了类似“readBundle:bad magic number”的错误。下面是一段代码片段

从类A传递包:

  Intent intent  = new Intent();
  Bundle b1=new Bundle();
  b1.putString("STORE_STATUS", "true");
  b1.putParcelableArrayList("ParticularStoreInfo", particularStoreInfoArr);
  intent.putExtra("BundleData", b1);
  intent.setAction(Tag);
  context.sendBroadcast(intent);
B类接收:

bundle = intent.getBundleExtra("BundleData");
if(bundle!=null){
String SEARCH_STATUS = bundle.getString("STORE_STATUS");// error on this line
if(SEARCH_STATUS.equalsIgnoreCase("true")){  


}
试试这个: 编辑:

要将数据发送到活动,请使用以下命令:

Intent intent = new Intent();
intent.putExtra("STORE_STATUS", "SOME DATAS");
您的问题答案:

要使用Bundle发送您想要的数据,您必须像这样使用:

Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.extras.putString(key, value);
mIntent.putExtras(mBundle);
意图从一个组件发送到另一个组件(不是在两个类之间) 一般而言)。假设B是广播接收器(您已使用 sendBroadcast)和A作为发送方,B必须在 sendBroadcast()

您已经使用了putExtra、putString和PutParceableAryList。那么 接收端,尝试使用getExtra、getString和 GetParceleaLearRayList

如果您试图在接收方方法上使用意图包 没有意图作为参数,可以使用getIntent()

如果您对这个答案感到困惑,请将您的完整答案或 要解析的示例代码,否则忽略


我做过这样的事。。类似于您的建议Bundle=getIntent().getExtras();如果(bundle!=null){String SEARCH_STATUS=bundle.getString(“STORE_STATUS”);如果(SEARCH_STATUS!=null){//do stuff}现在在SEARCH_STATUS上获得空指针异常它现在正在工作,但为什么每当我在bundle内发送任何parceble对象时,它在接收器上接收空指针异常。
Intent mIntent = new Intent(this, Example.class);
Bundle mBundle = new Bundle();
mBundle.extras.putString(key, value);
mIntent.putExtras(mBundle);