问题
I have a registered BroadcastReceiver
in my main activity. Activity sends a sticky in one of the tabs to trigger the broadcast receiver (TabActivity
application).
Everything works fine, but when I restart the app the sticky is sent automatically (not triggered by user) and view is opened.
My question is: how is that possible? Did I misunderstand something? And how can I fix that?
MainActivity: OnCreate:
registerReceiver(openOutgoingCall, new IntentFilter("OPENOUTGOINGCALL"));
BroadcastReceiver:
private BroadcastReceiver openOutgoingCall = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
Bundle extras = intent.getExtras();
if(extras.isEmpty() == false) {
HashMap<String,String> callData = (HashMap<String, String>) extras.get("callData");
openOutgoingCall(callData);
}
}
};
Activity inside TabHost
public void openCall(View view) {
Intent i = new Intent("OPENOUTGOINGCALL");
i.putExtra("callData", detailInfo);
sendStickyBroadcast(i);
}
回答1:
Sticky broadcasts are supposed to stay around (even they are received) so that they can be retrieved afterwards too. Perhaps you should try the simple way of broadcasting using:
sendBroadcast(i);
Read this.
来源:https://stackoverflow.com/questions/12490081/broadcast-receiver-is-triggered-automatically-on-start