代码之家  ›  专栏  ›  技术社区  ›  rayman

在处理程序内广播意图

  •  0
  • rayman  · 技术社区  · 15 年前

    我不能这么做,因为我是一个处理者,我正在失去我的活动范围。

    你知道我怎样才能实现这个想法吗?

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

    如果通过handler广播不起作用,欢迎任何其他想法,

    谢谢。

    1 回复  |  直到 15 年前
        1
  •  0
  •   rayman    15 年前

    这是我的错, 我可以在处理程序内部使用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);
        }
    };