在处理程序内部广播意图

时间:2010-10-25 13:28:34

标签: android

我在一个活动中有一个处理程序,我想使用sendBroadcast来启动另一个应用程序的接收者(不同的APK)。

我不能这样做,因为我进入Handler并且我失去了我的活动范围。

知道如何实现这个想法吗?

一些代码:

private Handler mHandler = new Handler() {
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case INSTALL_COMPLETE:
                 // here I wanna start my extern application via broadcasting!!

                startApplication();
                break;
            default:
                break;
        }
    }

如果广播不通过处理程序工作,那么欢迎任何其他想法,

感谢。

1 个答案:

答案 0 :(得分:0)

这是我的错, 我可以在Handler中使用startBroadcast / application / service。

非常感谢:

 private final int INSTALL_COMPLETE = 1;
private Handler mHandler = new Handler()
{
    public void handleMessage(Message msg)
    {
        switch (msg.what)
        {
            case INSTALL_COMPLETE:

                // finish the activity posting result
                // setResultAndFinish(msg.arg1);
                startApplication();
                break;
            default:
                break;
        }
    }

    private void startApplication()
    {
        String intentName = g_szIntentName;
        Intent i = new Intent(intentName);
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        sendBroadcast(i);
    }
};