这是一个正常运作的
private BroadcastReceiver onNotice= new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
String testeBroadcast = intent.getAction();
if (testeBroadcast.equals("Loadscreen"))
{
alertLoad.cancel();
}
fill_Main_TextV();
}
};
这是从这里发出的
MainActivity testeActivity = new MainActivity();
public static final String intService = "Loadscreen";
public Loadscreen()
{
super(intService);
// TODO Auto-generated constructor stub
}
@Override
protected void onHandleIntent(Intent intent)
{
testeActivity.fill_tabcli();
Intent in = new Intent(intService);
LocalBroadcastManager.getInstance(this).sendBroadcast(in);
}
我做过的BroadcastReceiver的变化是:
private BroadcastReceiver onNotice= new BroadcastReceiver()
{
@Override
public void onReceive(Context context, Intent intent)
{
String testeBroadcast = intent.getAction();
if (testeBroadcast.equals("Loadscreen"))
{
alertLoad.cancel();
}
if (testeBroadcast.equals("Accoes"));
{
CliInfo cliente = GlobalVars.getClientes_Info().get(GlobalVars.get_selected_client()+"");
for (String idAccoes : nomeficheiros)
{
for(accoes_cli teste : cliente.getAccoes())
{
int cliIdAccoes = teste.getId_accao();
if (idAccoes.equals(cliIdAccoes+""))
{
cliente.getAccoes().remove(teste);
}
}
}
}
fill_Main_TextV();
}
};
第二个sendBroadcast是:
public void escreve()
{
String esc_data = GlobalVars.year+"-"+GlobalVars.month+"-"+GlobalVars.day;
esc_data=GlobalFunctions.converte_data(esc_data);
try
{
writer = new FileWriter(GlobalVars.folder + "/" + esc_id + "_" + esc_data + ".acc");
writer.write(esc_accao + ";" + esc_resultado + ";" + esc_c1 + ";" + esc_c2 + ";" + esc_c3);
writer.flush();
writer.close();
}
catch (IOException e)
{
e.printStackTrace();
GlobalFunctions.toast_message(contexto, contexto.getString(R.string.accoes_salvo_erro));
}
finally
{
GlobalFunctions.toast_message(contexto, contexto.getString(R.string.accoes_salvo));
MainActivity.nomeficheiros.add(esc_id);
Intent in = new Intent(intService);
LocalBroadcastManager.getInstance(this).sendBroadcast(in);
}
}
我做错了什么? BoreadcastReceiver是否只能处理1个(总计)?