广播接收器在启动时自动触发 [英] Broadcast receiver is triggered automatically on start

查看:127
本文介绍了广播接收器在启动时自动触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的主要活动是注册了 BroadcastReceiver 。活动在其中一个选项卡中发送了一个即时贴以触发广播接收器( TabActivity 应用程序)。

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:

MainActivity: OnCreate:

    registerReceiver(openOutgoingCall, new IntentFilter("OPENOUTGOINGCALL"));

BroadcastReceiver:

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); 
            }

        }
    };

TabHost内部的活动

Activity inside TabHost

public void openCall(View view) {
    Intent i = new Intent("OPENOUTGOINGCALL");
    i.putExtra("callData", detailInfo);
    sendStickyBroadcast(i);    
}


推荐答案

粘性广播应该保留周围(甚至收到),以便以后也可以检索它们。也许您应该尝试使用以下简单的广播方式:

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);

阅读这个

这篇关于广播接收器在启动时自动触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆